-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use warpRequirePrimaryNetworkSigners config #537
Changes from 6 commits
16e661b
1e6f3cf
45889ae
b0e5071
8dfb194
d4da0a2
7a85734
b4c7a09
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,6 @@ import ( | |
"github.com/ava-labs/awm-relayer/peers" | ||
|
||
"github.com/ava-labs/avalanchego/ids" | ||
"github.com/ava-labs/avalanchego/utils/constants" | ||
"github.com/ava-labs/avalanchego/utils/logging" | ||
"github.com/ava-labs/avalanchego/utils/set" | ||
|
||
|
@@ -156,31 +155,25 @@ func (c *Config) GetSubnetID(blockchainID ids.ID) ids.ID { | |
} | ||
|
||
// If the numerator in the Warp config is 0, use the default value | ||
func calculateQuorumNumerator(cfgNumerator uint64) uint64 { | ||
func calculateQuorum(cfgNumerator uint64) WarpQuorum { | ||
if cfgNumerator == 0 { | ||
return warp.WarpDefaultQuorumNumerator | ||
} | ||
return cfgNumerator | ||
} | ||
|
||
// Helper to retrieve the Warp Quorum from the chain config. | ||
// Differentiates between subnet-evm and coreth RPC internally | ||
func getWarpQuorum( | ||
subnetID ids.ID, | ||
blockchainID ids.ID, | ||
client ethclient.Client, | ||
) (WarpQuorum, error) { | ||
if subnetID == constants.PrimaryNetworkID { | ||
return WarpQuorum{ | ||
QuorumNumerator: warp.WarpDefaultQuorumNumerator, | ||
QuorumDenominator: warp.WarpQuorumDenominator, | ||
}, nil | ||
} | ||
} else { | ||
return WarpQuorum{ | ||
QuorumNumerator: cfgNumerator, | ||
QuorumDenominator: warp.WarpQuorumDenominator, | ||
} | ||
} | ||
iansuvak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
func getWarpConfig(client ethclient.Client) (*warp.Config, error) { | ||
// Fetch the subnet's chain config | ||
chainConfig, err := client.ChainConfig(context.Background()) | ||
if err != nil { | ||
return WarpQuorum{}, fmt.Errorf("failed to fetch chain config for blockchain %s: %w", blockchainID, err) | ||
return nil, fmt.Errorf("failed to fetch chain config") | ||
} | ||
|
||
// First, check the list of precompile upgrades to get the most up to date Warp config | ||
|
@@ -202,27 +195,21 @@ func getWarpQuorum( | |
} | ||
} | ||
if warpConfig != nil { | ||
return WarpQuorum{ | ||
QuorumNumerator: calculateQuorumNumerator(warpConfig.QuorumNumerator), | ||
QuorumDenominator: warp.WarpQuorumDenominator, | ||
}, nil | ||
return warpConfig, nil | ||
} | ||
|
||
// If we didn't find the Warp config in the upgrade precompile list, check the genesis config | ||
warpConfig, ok := chainConfig.GenesisPrecompiles[warpConfigKey].(*warp.Config) | ||
if ok { | ||
return WarpQuorum{ | ||
QuorumNumerator: calculateQuorumNumerator(warpConfig.QuorumNumerator), | ||
QuorumDenominator: warp.WarpQuorumDenominator, | ||
}, nil | ||
if !ok { | ||
return nil, fmt.Errorf("no Warp config found in chain config") | ||
} | ||
return WarpQuorum{}, fmt.Errorf("failed to find warp config for blockchain %s", blockchainID) | ||
return warpConfig, nil | ||
} | ||
|
||
func (c *Config) InitializeWarpQuorums() error { | ||
// Initializes Warp configurations (quorum and self-signing settings) for each destination subnet | ||
func (c *Config) InitializeWarpConfigs() error { | ||
// Fetch the Warp quorum values for each destination subnet. | ||
for _, destinationSubnet := range c.DestinationBlockchains { | ||
err := destinationSubnet.initializeWarpQuorum() | ||
err := destinationSubnet.initializeWarpConfigs() | ||
if err != nil { | ||
return fmt.Errorf( | ||
"failed to initialize Warp quorum for destination subnet %s: %w", | ||
|
@@ -256,6 +243,15 @@ func (c *Config) GetWarpQuorum(blockchainID ids.ID) (WarpQuorum, error) { | |
return WarpQuorum{}, errFailedToGetWarpQuorum | ||
} | ||
|
||
func (c *Config) GetWarpRequirePrimaryNetworkSigners(blockchainID ids.ID) (bool, error) { | ||
for _, s := range c.DestinationBlockchains { | ||
if blockchainID.String() == s.BlockchainID { | ||
return s.warpRequirePrimaryNetworkSigners, nil | ||
} | ||
} | ||
iansuvak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return false, errFailedToGetWarpQuorum | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this error should say anything about the Warp Quorum. We error here iff the destination blockchain is in the config. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated the wording to indicate that the blockchainID is not in the destination blockchains. Thanks! |
||
} | ||
|
||
var _ peers.Config = &Config{} | ||
|
||
func (c *Config) GetPChainAPI() *basecfg.APIConfig { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's probably an indication we should be able to fetch them from the config together?
I also agree with your comment that the current
WarpQuorum
object is unnecessary. We can just use a uint forQuorumPercentage
, or haveWarpQuorum
contain the percentage andrequirePrimaryNetworkSigners
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went with the latter route and renamed it to
WarpConfig
. It's basically identical to the sourceWarpConfig
defined insubnet-evm
but doesn't implement theUpgrade
interface and when converting it we populate it withwarpDefaultQuorumNumerator
value if it's 0