Skip to content

Commit

Permalink
Integrate stake weighted gossip selection (#511)
Browse files Browse the repository at this point in the history
* Integrate stake weighted gossip selection

* nit

* merged

* add validity check
  • Loading branch information
StephenButtolph authored and ceyonur committed Mar 22, 2024
1 parent d85f60f commit 63bbcf1
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
4 changes: 0 additions & 4 deletions peer/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -882,10 +882,6 @@ func (t testAppSender) SendCrossChainAppResponse(_ context.Context, chainID ids.
return t.sendCrossChainAppResponseFn(chainID, requestID, appResponseBytes)
}

func (t testAppSender) SendAppGossipSpecific(context.Context, set.Set[ids.NodeID], []byte) error {
panic("not implemented")
}

func (t testAppSender) SendAppRequest(ctx context.Context, nodeIDs set.Set[ids.NodeID], requestID uint32, message []byte) error {
return t.sendAppRequestFn(ctx, nodeIDs, requestID, message)
}
Expand Down
6 changes: 6 additions & 0 deletions plugin/evm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const (
defaultMaxBlocksPerRequest = 0 // Default to no maximum on the number of blocks per getLogs request
defaultContinuousProfilerFrequency = 15 * time.Minute
defaultContinuousProfilerMaxFiles = 5
defaultPushGossipPercentStake = .9
defaultPushGossipNumValidators = 100
defaultPushGossipNumPeers = 0
defaultPushRegossipNumValidators = 10
Expand Down Expand Up @@ -154,6 +155,7 @@ type Config struct {
KeystoreInsecureUnlockAllowed bool `json:"keystore-insecure-unlock-allowed"`

// Gossip Settings
PushGossipPercentStake float64 `json:"push-gossip-percent-stake"`
PushGossipNumValidators int `json:"push-gossip-num-validators"`
PushGossipNumPeers int `json:"push-gossip-num-peers"`
PushRegossipNumValidators int `json:"push-regossip-num-validators"`
Expand Down Expand Up @@ -260,6 +262,7 @@ func (c *Config) SetDefaults() {
c.AcceptorQueueLimit = defaultAcceptorQueueLimit
c.CommitInterval = defaultCommitInterval
c.SnapshotWait = defaultSnapshotWait
c.PushGossipPercentStake = defaultPushGossipPercentStake
c.PushGossipNumValidators = defaultPushGossipNumValidators
c.PushGossipNumPeers = defaultPushGossipNumPeers
c.PushRegossipNumValidators = defaultPushRegossipNumValidators
Expand Down Expand Up @@ -317,5 +320,8 @@ func (c *Config) Validate() error {
return fmt.Errorf("cannot use commit interval of 0 with pruning enabled")
}

if c.PushGossipPercentStake < 0 || c.PushGossipPercentStake > 1 {
return fmt.Errorf("push-gossip-percent-stake is %f but must be in the range [0, 1]", c.PushGossipPercentStake)
}
return nil
}
2 changes: 2 additions & 0 deletions plugin/evm/gossiper_eth_gossiping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
commonEng "github.com/ava-labs/avalanchego/snow/engine/common"
"github.com/ava-labs/avalanchego/utils/set"

commonEng "github.com/ava-labs/avalanchego/snow/engine/common"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/rlp"
Expand Down
18 changes: 14 additions & 4 deletions plugin/evm/tx_gossip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,12 @@ func TestEthTxGossip(t *testing.T) {
return 0, nil
}
validatorState.GetValidatorSetF = func(context.Context, uint64, ids.ID) (map[ids.NodeID]*validators.GetValidatorOutput, error) {
return map[ids.NodeID]*validators.GetValidatorOutput{requestingNodeID: &validators.GetValidatorOutput{
NodeID: requestingNodeID,
Weight: 1,
}}, nil
return map[ids.NodeID]*validators.GetValidatorOutput{
requestingNodeID: {
NodeID: requestingNodeID,
Weight: 1,
},
}, nil
}

// Ask the VM for any new transactions. We should get nothing at first.
Expand Down Expand Up @@ -152,6 +154,14 @@ func TestEthTxPushGossipOutbound(t *testing.T) {
require := require.New(t)
ctx := context.Background()
snowCtx := utils.TestSnowContext()
snowCtx.ValidatorState = &validators.TestState{
GetCurrentHeightF: func(context.Context) (uint64, error) {
return 0, nil
},
GetValidatorSetF: func(context.Context, uint64, ids.ID) (map[ids.NodeID]*validators.GetValidatorOutput, error) {
return nil, nil
},
}
sender := &common.FakeSender{
SentAppGossip: make(chan []byte, 1),
}
Expand Down
5 changes: 3 additions & 2 deletions plugin/evm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,8 +688,9 @@ func (vm *VM) initBlockBuilding() error {
}()

pushGossipParams := gossip.BranchingFactor{
Validators: vm.config.PushGossipNumValidators,
Peers: vm.config.PushGossipNumPeers,
StakePercentage: vm.config.PushGossipPercentStake,
Validators: vm.config.PushGossipNumValidators,
Peers: vm.config.PushGossipNumPeers,
}
pushRegossipParams := gossip.BranchingFactor{
Validators: vm.config.PushRegossipNumValidators,
Expand Down

0 comments on commit 63bbcf1

Please sign in to comment.