-
Notifications
You must be signed in to change notification settings - Fork 734
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
node: generalised governance #3895
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1fc0df9
node/admin: add generalised EVM call governance handler
kcsongor 62fd2b9
node/admin: add admin template for evm governance call
kcsongor 3c3de23
node/admin: add generalised Solana call governance handler
kcsongor e1c8bc8
node/admin: check address lengths and fix typo in governance handler
kcsongor 2bc1d0a
node/admin: better error handling and fix comments
kcsongor 51d34bf
sdk/vaa: add constants for general purpose governance actions
kcsongor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -577,6 +577,58 @@ func wormholeRelayerSetDefaultDeliveryProvider(req *nodev1.WormholeRelayerSetDef | |
return v, nil | ||
} | ||
|
||
func evmCallToVaa(evmCall *nodev1.EvmCall, timestamp time.Time, guardianSetIndex, nonce uint32, sequence uint64) (*vaa.VAA, error) { | ||
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. Can we add a check in here to enforce that chain id doesn't exceed max uint16? |
||
governanceContract := ethcommon.HexToAddress(evmCall.GovernanceContract) | ||
targetContract := ethcommon.HexToAddress(evmCall.TargetContract) | ||
|
||
payload, err := hex.DecodeString(evmCall.AbiEncodedCall) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to decode ABI encoded call: %w", err) | ||
} | ||
|
||
body, err := vaa.BodyGeneralPurposeGovernanceEvm{ | ||
ChainID: vaa.ChainID(evmCall.ChainId), | ||
GovernanceContract: governanceContract, | ||
TargetContract: targetContract, | ||
Payload: payload, | ||
}.Serialize() | ||
|
||
if err != nil { | ||
return nil, fmt.Errorf("failed to serialize governance body: %w", err) | ||
} | ||
|
||
v := vaa.CreateGovernanceVAA(timestamp, nonce, sequence, guardianSetIndex, body) | ||
|
||
return v, nil | ||
} | ||
|
||
func solanaCallToVaa(solanaCall *nodev1.SolanaCall, timestamp time.Time, guardianSetIndex, nonce uint32, sequence uint64) (*vaa.VAA, error) { | ||
address, err := base58.Decode(solanaCall.GovernanceContract) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to decode base58 governance contract address: %w", err) | ||
} | ||
if len(address) != 32 { | ||
return nil, errors.New("invalid governance contract address length (expected 32 bytes)") | ||
} | ||
|
||
var governanceContract [32]byte | ||
copy(governanceContract[:], address) | ||
kcsongor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
instruction, err := hex.DecodeString(solanaCall.EncodedInstruction) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to decode instruction: %w", err) | ||
} | ||
|
||
v := vaa.CreateGovernanceVAA(timestamp, nonce, sequence, guardianSetIndex, | ||
vaa.BodyGeneralPurposeGovernanceSolana{ | ||
ChainID: vaa.ChainID(solanaCall.ChainId), | ||
GovernanceContract: governanceContract, | ||
Instruction: instruction, | ||
}.Serialize()) | ||
|
||
return v, nil | ||
} | ||
|
||
func GovMsgToVaa(message *nodev1.GovernanceMessage, currentSetIndex uint32, timestamp time.Time) (*vaa.VAA, error) { | ||
var ( | ||
v *vaa.VAA | ||
|
@@ -620,6 +672,10 @@ func GovMsgToVaa(message *nodev1.GovernanceMessage, currentSetIndex uint32, time | |
v, err = ibcUpdateChannelChain(payload.IbcUpdateChannelChain, timestamp, currentSetIndex, message.Nonce, message.Sequence) | ||
case *nodev1.GovernanceMessage_WormholeRelayerSetDefaultDeliveryProvider: | ||
v, err = wormholeRelayerSetDefaultDeliveryProvider(payload.WormholeRelayerSetDefaultDeliveryProvider, timestamp, currentSetIndex, message.Nonce, message.Sequence) | ||
case *nodev1.GovernanceMessage_EvmCall: | ||
v, err = evmCallToVaa(payload.EvmCall, timestamp, currentSetIndex, message.Nonce, message.Sequence) | ||
case *nodev1.GovernanceMessage_SolanaCall: | ||
v, err = solanaCallToVaa(payload.SolanaCall, timestamp, currentSetIndex, message.Nonce, message.Sequence) | ||
default: | ||
panic(fmt.Sprintf("unsupported VAA type: %T", payload)) | ||
} | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why are we not using
parseAddress
in these templates?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.
because
parseAddress
attempts to parse any 32 byte address-like thing into a (left-padded) 32 byte addresswormhole/node/cmd/guardiand/admintemplate.go
Lines 1061 to 1084 in 51d34bf
in this case, we only care about EVM addresses, so we can be a bit more specific