Skip to content
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: Extend flow cancel by configuring allow-list of chain ID pairs ("pipes") #4229

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
3 changes: 2 additions & 1 deletion node/pkg/db/governor.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ type Transfer struct {
MsgID string
Hash string
TargetAddress vaa.Address
TargetChain vaa.ChainID
// The destination chain.
TargetChain vaa.ChainID
}

func (t *Transfer) Marshal() ([]byte, error) {
Expand Down
9 changes: 7 additions & 2 deletions node/pkg/governor/devnet_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/wormhole-foundation/wormhole/sdk/vaa"
)

func (gov *ChainGovernor) initDevnetConfig() ([]tokenConfigEntry, []tokenConfigEntry, []chainConfigEntry) {
func (gov *ChainGovernor) initDevnetConfig() ([]tokenConfigEntry, []tokenConfigEntry, []chainConfigEntry, []pipe) {
gov.logger.Info("setting up devnet config")

gov.dayLengthInMinutes = 5
Expand All @@ -18,16 +18,21 @@ func (gov *ChainGovernor) initDevnetConfig() ([]tokenConfigEntry, []tokenConfigE
}

flowCancelTokens := []tokenConfigEntry{}
flowCancelPipes := []pipe{}
if gov.flowCancelEnabled {
flowCancelTokens = []tokenConfigEntry{
{chain: 1, addr: "3b442cb3912157f13a933d0134282d032b5ffecd01a2dbf1b7790608df002ea7", symbol: "USDC", coinGeckoId: "usd-coin", decimals: 6, price: 1.001}, // Addr: 4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU, Notional: 6780118.197035182
}

flowCancelPipes = []pipe{
{first: vaa.ChainIDEthereum, second: vaa.ChainIDSui},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a question. Does it make sense to have Sui here when the governor is not enabled for it in the devnet config?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not, thanks for catching this.

}
}

chains := []chainConfigEntry{
{emitterChainID: vaa.ChainIDSolana, dailyLimit: 100, bigTransactionSize: 75},
{emitterChainID: vaa.ChainIDEthereum, dailyLimit: 100000},
}

return tokens, flowCancelTokens, chains
return tokens, flowCancelTokens, chains, flowCancelPipes
}
35 changes: 35 additions & 0 deletions node/pkg/governor/flow_cancel_pipes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package governor

import (
"github.com/wormhole-foundation/wormhole/sdk/vaa"
)

// FlowCancelPipes returns a list of `pipe`s representing a pair of chains for which flow canceling is enabled.
// In practice this list should contain pairs of chains that have a large amount of volume between each other.
// These are more likely to cause chronic congestion which flow canceling can help to alleviate.
// Pairs of chains that are not frequently congested do not need to enable flow canceling as they should have
// plenty of regular Governor capacity to work with.
func FlowCancelPipes() []pipe {
return []pipe{
{first: vaa.ChainIDEthereum, second: vaa.ChainIDSui},
}
}

func Valid(input []pipe) bool {
seen := make([]pipe, 10)
for _, p := range input {
// This check is needed when there is exactly one pipe. Otherwise, the seen loop detects this.
if !p.valid() {
return false
}
for _, s := range seen {
// Note that equals() also checks that both pipes are valid.
if p.equals(&s) {
return false
}
}

seen = append(seen, p)
}
return true
}
109 changes: 109 additions & 0 deletions node/pkg/governor/flow_cancel_pipes_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package governor

import (
"testing"

"github.com/stretchr/testify/require"
"github.com/wormhole-foundation/wormhole/sdk/vaa"
)

func TestFlowCancelPipesMainnetDeployment(t *testing.T) {

tests := map[string][]pipe{
"expected mainnet values": {
{
vaa.ChainIDEthereum,
vaa.ChainIDSui,
},
},
}
for name, expected := range tests {
t.Run(name, func(t *testing.T) {
got := FlowCancelPipes()
// Basic validity check.
require.True(t, Valid(got))

// Check that values are what we expected.
require.Equal(t, 1, len(got))
require.True(t, got[0].equals(&expected[0]))
})
}
}

func TestValid(t *testing.T) {
tests := []struct {
name string
args []pipe
want bool
}{
{
name: "error: duplicate pipes",
args: []pipe{
{
first: vaa.ChainIDEthereum,
second: vaa.ChainIDSolana,
},
{
first: vaa.ChainIDEthereum,
second: vaa.ChainIDSolana,
},
},
want: false,
},
{
name: "error: duplicate pipes, different order",
args: []pipe{
{
first: vaa.ChainIDEthereum,
second: vaa.ChainIDSolana,
},
{
first: vaa.ChainIDSolana,
second: vaa.ChainIDEthereum,
},
},
want: false,
},
{
name: "error: invalid pipe (ends are the same)",
args: []pipe{
{
first: vaa.ChainIDEthereum,
second: vaa.ChainIDEthereum,
},
},
want: false,
},
{
name: "error: invalid pipe (unset)",
args: []pipe{
{
first: vaa.ChainIDEthereum,
second: vaa.ChainIDUnset,
},
},
want: false,
},
{
name: "happy path",
args: []pipe{
{
first: vaa.ChainIDEthereum,
second: vaa.ChainIDSui,
},
{
first: vaa.ChainIDEthereum,
second: vaa.ChainIDSolana,
},
},
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := Valid(tt.args); got != tt.want {
require.Equal(t, tt.want, got, "want %v got %v value %v", tt.want, got, tt.args)
}
})
}
}
Loading
Loading