From 259f85f017ea5f26c05e6f77e2105c37f37e570d Mon Sep 17 00:00:00 2001 From: Darioush Jalali Date: Wed, 24 Jan 2024 16:21:44 -0800 Subject: [PATCH] avago bump: Bloom filter metrics + Durango time --- go.mod | 4 ++-- go.sum | 8 ++++---- params/config.go | 22 +++++++++++++++++++++- params/network_upgrades.go | 26 -------------------------- plugin/evm/gossip.go | 5 +++-- plugin/evm/gossip_test.go | 5 +++-- plugin/evm/tx_gossip_test.go | 2 +- plugin/evm/vm.go | 22 ++++------------------ scripts/versions.sh | 2 +- 9 files changed, 39 insertions(+), 57 deletions(-) diff --git a/go.mod b/go.mod index 80178b71c1..40e60a5eb4 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.20 require ( github.com/VictoriaMetrics/fastcache v1.10.0 github.com/ava-labs/avalanche-network-runner v1.7.4-rc.0 - github.com/ava-labs/avalanchego v1.10.18 + github.com/ava-labs/avalanchego v1.10.19-legacy-upgrade-times github.com/cespare/cp v0.1.0 github.com/davecgh/go-spew v1.1.1 github.com/deckarep/golang-set/v2 v2.1.0 @@ -54,7 +54,7 @@ require ( github.com/DataDog/zstd v1.5.2 // indirect github.com/Microsoft/go-winio v0.5.2 // indirect github.com/NYTimes/gziphandler v1.1.1 // indirect - github.com/ava-labs/coreth v0.12.10-rc.5 // indirect + github.com/ava-labs/coreth v0.12.10-wip-bloom-metrics // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/bits-and-blooms/bitset v1.7.0 // indirect github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect diff --git a/go.sum b/go.sum index e8878e5341..1a1e05224c 100644 --- a/go.sum +++ b/go.sum @@ -61,10 +61,10 @@ github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kd github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/ava-labs/avalanche-network-runner v1.7.4-rc.0 h1:xNbCMNqenaDr0bb35j27sqwa+C8t8BgRz51vXd6q0QM= github.com/ava-labs/avalanche-network-runner v1.7.4-rc.0/go.mod h1:B7Ynk/avkCk49CCIWbM4j1UrPlqIi0IHCPAB2MZNvLw= -github.com/ava-labs/avalanchego v1.10.18 h1:ErJ+SJBtN9tVqk3OPRXffpf+MWeQnNZJlBNWQIgAg8A= -github.com/ava-labs/avalanchego v1.10.18/go.mod h1:wqmokVcLXE+9Nfa8wHdGJtjEW35acVf8rkraSZPVBA4= -github.com/ava-labs/coreth v0.12.10-rc.5 h1:FMVvXHssvMQ3Eade7i85Wsx9tuD3kUOFMG8ktHeDTp8= -github.com/ava-labs/coreth v0.12.10-rc.5/go.mod h1:a58HbIBc9jscGc3aL8e7JuG8RfhBBOm63waq1q0YM+U= +github.com/ava-labs/avalanchego v1.10.19-legacy-upgrade-times h1:VWI/+vOP63QzrHK2HFw+So+qK1f8gKGpFmdvrKFzOM8= +github.com/ava-labs/avalanchego v1.10.19-legacy-upgrade-times/go.mod h1:bxbOXEYGnwz0K6uPsiB56Ig3pQbBfi4P8NOLtRNhNgw= +github.com/ava-labs/coreth v0.12.10-wip-bloom-metrics h1:uSISbdHpLVlTkwUUqVonMgdX91ePbgP/qJ7iHup9xS4= +github.com/ava-labs/coreth v0.12.10-wip-bloom-metrics/go.mod h1:bw3pxnF+IBw5SoxAKujUiZPbPimieJHPd9fQWZZ/MOM= github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= diff --git a/params/config.go b/params/config.go index c027badfba..47c35c343c 100644 --- a/params/config.go +++ b/params/config.go @@ -31,8 +31,11 @@ import ( "errors" "fmt" "math/big" + "time" "github.com/ava-labs/avalanchego/snow" + "github.com/ava-labs/avalanchego/utils/constants" + "github.com/ava-labs/avalanchego/version" "github.com/ava-labs/subnet-evm/commontype" "github.com/ava-labs/subnet-evm/precompile/modules" "github.com/ava-labs/subnet-evm/precompile/precompileconfig" @@ -86,7 +89,7 @@ var ( PetersburgBlock: big.NewInt(0), IstanbulBlock: big.NewInt(0), MuirGlacierBlock: big.NewInt(0), - MandatoryNetworkUpgrades: MainnetNetworkUpgrades, // This can be changed to correct network (local, test) via VM. + MandatoryNetworkUpgrades: GetMandatoryNetworkUpgrades(constants.MainnetID), // This can be changed to correct network (local, test) via VM. GenesisPrecompiles: Precompiles{}, } @@ -155,6 +158,23 @@ var ( TestRules = TestChainConfig.AvalancheRules(new(big.Int), 0) ) +func getUpgradeTime(networkID uint32, upgradeTimes map[uint32]time.Time) *uint64 { + if upgradeTime, ok := upgradeTimes[networkID]; ok { + return utils.TimeToNewUint64(upgradeTime) + } + // If the upgrade time isn't specified, default being enabled in the + // genesis. + return utils.NewUint64(0) +} + +// GetMandatoryNetworkUpgrades returns the mandatory network upgrades for the specified network ID. +func GetMandatoryNetworkUpgrades(networkID uint32) MandatoryNetworkUpgrades { + return MandatoryNetworkUpgrades{ + SubnetEVMTimestamp: utils.NewUint64(0), + DurangoTimestamp: getUpgradeTime(networkID, version.DurangoTimes), + } +} + // UpgradeConfig includes the following configs that may be specified in upgradeBytes: // - Timestamps that enable avalanche network upgrades, // - Enabling or disabling precompiles as network upgrades. diff --git a/params/network_upgrades.go b/params/network_upgrades.go index 71a52f0a02..41a4366cb5 100644 --- a/params/network_upgrades.go +++ b/params/network_upgrades.go @@ -3,32 +3,6 @@ package params -import ( - "github.com/ava-labs/subnet-evm/utils" -) - -var ( - LocalNetworkUpgrades = MandatoryNetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(0), - DurangoTimestamp: utils.NewUint64(0), - } - - FujiNetworkUpgrades = MandatoryNetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(0), - // DurangoTimestamp: utils.NewUint64(0), // TODO: Uncomment and set this to the correct value - } - - MainnetNetworkUpgrades = MandatoryNetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(0), - // DurangoTimestamp: utils.NewUint64(0), // TODO: Uncomment and set this to the correct value - } - - UnitTestNetworkUpgrades = MandatoryNetworkUpgrades{ - SubnetEVMTimestamp: utils.NewUint64(0), - DurangoTimestamp: utils.NewUint64(0), - } -) - // MandatoryNetworkUpgrades contains timestamps that enable mandatory network upgrades. // These upgrades are mandatory, meaning that if a node does not upgrade by the // specified timestamp, it will be unable to participate in consensus. diff --git a/plugin/evm/gossip.go b/plugin/evm/gossip.go index c1d1585e2b..80305f41ca 100644 --- a/plugin/evm/gossip.go +++ b/plugin/evm/gossip.go @@ -12,6 +12,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ethereum/go-ethereum/log" + "github.com/prometheus/client_golang/prometheus" "github.com/ava-labs/avalanchego/network/p2p" "github.com/ava-labs/avalanchego/network/p2p/gossip" @@ -84,8 +85,8 @@ func (t txGossipHandler) CrossChainAppRequest(context.Context, ids.ID, time.Time return nil, nil } -func NewGossipEthTxPool(mempool *txpool.TxPool) (*GossipEthTxPool, error) { - bloom, err := gossip.NewBloomFilter(txGossipBloomMinTargetElements, txGossipBloomTargetFalsePositiveRate, txGossipBloomResetFalsePositiveRate) +func NewGossipEthTxPool(mempool *txpool.TxPool, registerer prometheus.Registerer) (*GossipEthTxPool, error) { + bloom, err := gossip.NewBloomFilter(registerer, "eth_tx_bloom_filter", txGossipBloomMinTargetElements, txGossipBloomTargetFalsePositiveRate, txGossipBloomResetFalsePositiveRate) if err != nil { return nil, fmt.Errorf("failed to initialize bloom filter: %w", err) } diff --git a/plugin/evm/gossip_test.go b/plugin/evm/gossip_test.go index a9f80355e8..2dd95fc50b 100644 --- a/plugin/evm/gossip_test.go +++ b/plugin/evm/gossip_test.go @@ -19,6 +19,7 @@ import ( "github.com/ava-labs/subnet-evm/params" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" + "github.com/prometheus/client_golang/prometheus" "github.com/stretchr/testify/require" ) @@ -49,11 +50,11 @@ func TestGossipSubscribe(t *testing.T) { txPool.SetGasPrice(common.Big1) txPool.SetMinFee(common.Big0) - gossipTxPool, err := NewGossipEthTxPool(txPool) + gossipTxPool, err := NewGossipEthTxPool(txPool, prometheus.NewRegistry()) require.NoError(err) // use a custom bloom filter to test the bloom filter reset - gossipTxPool.bloom, err = gossip.NewBloomFilter(1, 0.01, 0.0000000000000001) // maxCount =1 + gossipTxPool.bloom, err = gossip.NewBloomFilter(prometheus.NewRegistry(), "", 1, 0.01, 0.0000000000000001) // maxCount =1 require.NoError(err) ctx, cancel := context.WithCancel(context.TODO()) defer cancel() diff --git a/plugin/evm/tx_gossip_test.go b/plugin/evm/tx_gossip_test.go index b0efc23717..54257b4bb2 100644 --- a/plugin/evm/tx_gossip_test.go +++ b/plugin/evm/tx_gossip_test.go @@ -82,7 +82,7 @@ func TestEthTxGossip(t *testing.T) { } // Ask the VM for any new transactions. We should get nothing at first. - emptyBloomFilter, err := gossip.NewBloomFilter(txGossipBloomMinTargetElements, txGossipBloomTargetFalsePositiveRate, txGossipBloomResetFalsePositiveRate) + emptyBloomFilter, err := gossip.NewBloomFilter(prometheus.NewRegistry(), "", txGossipBloomMinTargetElements, txGossipBloomTargetFalsePositiveRate, txGossipBloomResetFalsePositiveRate) require.NoError(err) emptyBloomFilterBytes, _ := emptyBloomFilter.Marshal() request := &sdk.PullGossipRequest{ diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index 8414ceef3b..68e81f2fb6 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -324,8 +324,9 @@ func (vm *VM) Initialize( g.Config = params.SubnetEVMDefaultChainConfig } - mandatoryNetworkUpgrades, enforce := getMandatoryNetworkUpgrades(chainCtx.NetworkID) - if enforce { + mandatoryNetworkUpgrades := params.GetMandatoryNetworkUpgrades(chainCtx.NetworkID) + if chainCtx.NetworkID == avalanchegoConstants.MainnetID || + chainCtx.NetworkID == avalanchegoConstants.FujiID { // We enforce network upgrades here, regardless of the chain config // provided in the genesis file g.Config.MandatoryNetworkUpgrades = mandatoryNetworkUpgrades @@ -693,7 +694,7 @@ func (vm *VM) initBlockBuilding() error { vm.builder.awaitSubmittedTxs() vm.Network.SetGossipHandler(NewGossipHandler(vm, gossipStats)) - ethTxPool, err := NewGossipEthTxPool(vm.txPool) + ethTxPool, err := NewGossipEthTxPool(vm.txPool, vm.sdkMetrics) if err != nil { return err } @@ -1091,18 +1092,3 @@ func attachEthService(handler *rpc.Server, apis []rpc.API, names []string) error return nil } - -// getMandatoryNetworkUpgrades returns the mandatory network upgrades for the specified network ID, -// along with a flag that indicates if returned upgrades should be strictly enforced. -func getMandatoryNetworkUpgrades(networkID uint32) (params.MandatoryNetworkUpgrades, bool) { - switch networkID { - case avalanchegoConstants.MainnetID: - return params.MainnetNetworkUpgrades, true - case avalanchegoConstants.FujiID: - return params.FujiNetworkUpgrades, true - case avalanchegoConstants.UnitTestID: - return params.UnitTestNetworkUpgrades, false - default: - return params.LocalNetworkUpgrades, false - } -} diff --git a/scripts/versions.sh b/scripts/versions.sh index d773bf1459..ed9e014559 100644 --- a/scripts/versions.sh +++ b/scripts/versions.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # Don't export them as they're used in the context of other calls -AVALANCHE_VERSION=${AVALANCHE_VERSION:-'v1.10.18'} +AVALANCHE_VERSION=${AVALANCHE_VERSION:-'v1.10.19-legacy-upgrade-times'} GINKGO_VERSION=${GINKGO_VERSION:-'v2.2.0'} # This won't be used, but it's here to make code syncs easier