Skip to content

Commit

Permalink
fix: assigning msgs to validators w/o chain support (#1023)
Browse files Browse the repository at this point in the history
  • Loading branch information
byte-bandit authored Nov 2, 2023
1 parent 3cb3059 commit b1dd505
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 7 deletions.
8 changes: 4 additions & 4 deletions x/evm/keeper/msg_assigner.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ type MsgAssigner struct {
}

func filterAssignableValidators(validators []valsettypes.Validator, chainID string, req *xchain.JobRequirements) []valsettypes.Validator {
if req == nil || req.EnforceMEVRelay == false {
return validators
}

return slice.Filter(validators, func(val valsettypes.Validator) bool {
for _, v := range val.ExternalChainInfos {
if v.ChainReferenceID != chainID {
continue
}

if req == nil || !req.EnforceMEVRelay {
return true
}

for _, t := range v.Traits {
if req.EnforceMEVRelay && t == valsettypes.PIGEON_TRAIT_MEV {
return true
Expand Down
111 changes: 108 additions & 3 deletions x/evm/keeper/msg_assigner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,12 +550,27 @@ func TestPickValidatorForMessage(t *testing.T) {
Validators: []valsettypes.Validator{
{
Address: sdk.ValAddress("testvalidator1"),
ExternalChainInfos: []*valsettypes.ExternalChainInfo{
{
ChainReferenceID: "test-chain",
},
},
},
{
Address: sdk.ValAddress("testvalidator2"),
ExternalChainInfos: []*valsettypes.ExternalChainInfo{
{
ChainReferenceID: "test-chain",
},
},
},
{
Address: sdk.ValAddress("testvalidator3"),
ExternalChainInfos: []*valsettypes.ExternalChainInfo{
{
ChainReferenceID: "test-chain",
},
},
},
},
}
Expand All @@ -571,6 +586,7 @@ func TestPickValidatorForMessage(t *testing.T) {
Uptime: "0.5",
Fee: "0.5",
},
chainID: "test-chain",
expected: sdk.ValAddress("testvalidator1").String(),
},
{
Expand Down Expand Up @@ -617,12 +633,27 @@ func TestPickValidatorForMessage(t *testing.T) {
Validators: []valsettypes.Validator{
{
Address: sdk.ValAddress("testvalidator1"),
ExternalChainInfos: []*valsettypes.ExternalChainInfo{
{
ChainReferenceID: "test-chain",
},
},
},
{
Address: sdk.ValAddress("testvalidator2"),
ExternalChainInfos: []*valsettypes.ExternalChainInfo{
{
ChainReferenceID: "test-chain",
},
},
},
{
Address: sdk.ValAddress("testvalidator3"),
ExternalChainInfos: []*valsettypes.ExternalChainInfo{
{
ChainReferenceID: "test-chain",
},
},
},
},
}
Expand All @@ -632,6 +663,7 @@ func TestPickValidatorForMessage(t *testing.T) {

return msgAssigner
},
chainID: "test-chain",
expected: sdk.ValAddress("testvalidator1").String(),
},
{
Expand All @@ -648,6 +680,11 @@ func TestPickValidatorForMessage(t *testing.T) {
Validators: []valsettypes.Validator{
{
Address: sdk.ValAddress("testvalidator1"),
ExternalChainInfos: []*valsettypes.ExternalChainInfo{
{
ChainReferenceID: "test-chain",
},
},
},
{
Address: sdk.ValAddress("testvalidator2"),
Expand All @@ -657,6 +694,11 @@ func TestPickValidatorForMessage(t *testing.T) {
},
{
Address: sdk.ValAddress("testvalidator3"),
ExternalChainInfos: []*valsettypes.ExternalChainInfo{
{
ChainReferenceID: "test-chain",
},
},
},
},
}
Expand Down Expand Up @@ -689,8 +731,8 @@ func TestPickValidatorForMessage(t *testing.T) {

actual, actualErr := messageAssigner.PickValidatorForMessage(ctx, tt.weights, tt.chainID, tt.requirements)

asserter.Equal(tt.expected, actual)
asserter.Equal(tt.expectedErr, actualErr)
asserter.Equal(tt.expected, actual, tt.name)
asserter.Equal(tt.expectedErr, actualErr, tt.name)
})
}
}
Expand All @@ -700,12 +742,27 @@ func TestFilterAssignableValidators(t *testing.T) {
defaultValidators := []valsettypes.Validator{
{
Address: sdk.ValAddress("validator-1"),
ExternalChainInfos: []*valsettypes.ExternalChainInfo{
{
ChainReferenceID: "test-chain",
},
},
},
{
Address: sdk.ValAddress("validator-2"),
ExternalChainInfos: []*valsettypes.ExternalChainInfo{
{
ChainReferenceID: "test-chain",
},
},
},
{
Address: sdk.ValAddress("validator-3"),
ExternalChainInfos: []*valsettypes.ExternalChainInfo{
{
ChainReferenceID: "test-chain",
},
},
},
}
tests := []struct {
Expand All @@ -720,7 +777,7 @@ func TestFilterAssignableValidators(t *testing.T) {
name: "with empty validator slice",
expectedStr: "should return empty slice",
validators: []valsettypes.Validator{},
expected: []valsettypes.Validator{},
expected: []valsettypes.Validator(nil),
requirements: nil,
chainID: chainID,
},
Expand Down Expand Up @@ -816,6 +873,54 @@ func TestFilterAssignableValidators(t *testing.T) {
requirements: &xchain.JobRequirements{EnforceMEVRelay: true},
chainID: chainID,
},
{
name: "with validators not supporting required chain ID",
expectedStr: "should remove validators without full chain support from result set",
validators: []valsettypes.Validator{
{
Address: sdk.ValAddress("validator-1"),
ExternalChainInfos: []*valsettypes.ExternalChainInfo{
{
ChainReferenceID: "other-chain",
},
},
},
{
Address: sdk.ValAddress("validator-2"),
ExternalChainInfos: []*valsettypes.ExternalChainInfo{
{
ChainReferenceID: "other-chain",
},
{
ChainReferenceID: chainID,
},
},
},
{
Address: sdk.ValAddress("validator-3"),
ExternalChainInfos: []*valsettypes.ExternalChainInfo{
{
ChainReferenceID: "other-chain",
},
},
},
},
expected: []valsettypes.Validator{
{
Address: sdk.ValAddress("validator-2"),
ExternalChainInfos: []*valsettypes.ExternalChainInfo{
{
ChainReferenceID: "other-chain",
},
{
ChainReferenceID: chainID,
},
},
},
},
requirements: nil,
chainID: chainID,
},
}

for k, v := range tests {
Expand Down

0 comments on commit b1dd505

Please sign in to comment.