From f36a199c2a531224564918a6466bdeac6e999149 Mon Sep 17 00:00:00 2001 From: Anshal Shukla Date: Sat, 13 Jan 2024 11:15:33 +0530 Subject: [PATCH 1/6] chg: make HF consistent --- params/config.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/params/config.go b/params/config.go index f6b663a653..7161c68c8d 100644 --- a/params/config.go +++ b/params/config.go @@ -960,9 +960,9 @@ func (c *ChainConfig) CheckConfigForkOrder() error { {name: "arrowGlacierBlock", block: c.ArrowGlacierBlock, optional: true}, {name: "grayGlacierBlock", block: c.GrayGlacierBlock, optional: true}, {name: "mergeNetsplitBlock", block: c.MergeNetsplitBlock, optional: true}, - {name: "ShanghaiBlock", block: c.ShanghaiBlock}, - {name: "CancunBlock", block: c.CancunBlock, optional: true}, - {name: "pragueTime", block: c.PragueBlock, optional: true}, + {name: "shanghaiBlock", block: c.ShanghaiBlock}, + {name: "cancunBlock", block: c.CancunBlock, optional: true}, + {name: "pragueBlock", block: c.PragueBlock, optional: true}, } { if lastFork.name != "" { switch { From 0980a5b3e592de130ea2541ee9394229630c16c4 Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Thu, 30 Nov 2023 15:35:46 +0530 Subject: [PATCH 2/6] allow unprotected txns --- core/txpool/legacypool/legacypool.go | 16 +++++++++++-- core/txpool/validation.go | 4 +++- core/types/transaction_signing.go | 35 ++++++++++++++++++++++++++++ eth/backend.go | 2 -- 4 files changed, 52 insertions(+), 5 deletions(-) diff --git a/core/txpool/legacypool/legacypool.go b/core/txpool/legacypool/legacypool.go index bf179fe996..6a3005e5a1 100644 --- a/core/txpool/legacypool/legacypool.go +++ b/core/txpool/legacypool/legacypool.go @@ -155,7 +155,8 @@ var DefaultConfig = Config{ AccountQueue: 64, GlobalQueue: 1024, - Lifetime: 3 * time.Hour, + Lifetime: 3 * time.Hour, + AllowUnprotectedTxs: false, } // sanitize checks the provided user configurations and changes anything that's @@ -601,7 +602,8 @@ func (pool *LegacyPool) local() map[common.Address]types.Transactions { // and does not require the pool mutex to be held. func (pool *LegacyPool) validateTxBasics(tx *types.Transaction, local bool) error { opts := &txpool.ValidationOptions{ - Config: pool.chainconfig, + Config: pool.chainconfig, + AllowUnprotectedTxs: pool.config.AllowUnprotectedTxs, Accept: 0 | 1< Date: Thu, 28 Mar 2024 15:19:36 +0530 Subject: [PATCH 3/6] add: commits back from reverted 'consistent' PR --- core/txpool/validation.go | 2 +- eth/backend.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/core/txpool/validation.go b/core/txpool/validation.go index aa718ca7f9..faace9cf8a 100644 --- a/core/txpool/validation.go +++ b/core/txpool/validation.go @@ -93,7 +93,7 @@ func ValidateTransaction(tx *types.Transaction, head *types.Header, signer types return core.ErrTipAboveFeeCap } // Make sure the transaction is signed properly - if _, err := types.Sender(signer, tx); err != nil || !opts.AllowUnprotectedTxs { + if _, err := types.Sender(signer, tx); err != nil && !opts.AllowUnprotectedTxs { return ErrInvalidSender } // Ensure the transaction has more gas than the bare minimum needed to cover diff --git a/eth/backend.go b/eth/backend.go index 4787b56ed8..484d45206a 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -174,6 +174,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { eth.APIBackend = &EthAPIBackend{stack.Config().ExtRPCEnabled(), stack.Config().AllowUnprotectedTxs, eth, nil} if eth.APIBackend.allowUnprotectedTxs { + log.Info("------Unprotected transactions allowed-------") config.TxPool.AllowUnprotectedTxs = true } From 120cbc7c012f4d324d956c1ccdf29a5bc9a07c73 Mon Sep 17 00:00:00 2001 From: Pratik Patil Date: Fri, 15 Dec 2023 12:49:11 +0530 Subject: [PATCH 4/6] test all default flags added via config file (#1105) --- internal/cli/server/config_legacy_test.go | 19 +++ internal/cli/server/testdata/default.toml | 193 ++++++++++++++++++++++ 2 files changed, 212 insertions(+) create mode 100644 internal/cli/server/testdata/default.toml diff --git a/internal/cli/server/config_legacy_test.go b/internal/cli/server/config_legacy_test.go index aa6cffc470..e9957c3353 100644 --- a/internal/cli/server/config_legacy_test.go +++ b/internal/cli/server/config_legacy_test.go @@ -42,3 +42,22 @@ func TestConfigLegacy(t *testing.T) { readFile("./testdata/test.toml") }) } + +func TestDefaultConfigLegacy(t *testing.T) { + readFile := func(path string) { + expectedConfig, err := readLegacyConfig(path) + assert.NoError(t, err) + + testConfig := DefaultConfig() + + testConfig.Identity = "Polygon-Devs" + testConfig.DataDir = "/var/lib/bor" + + assert.Equal(t, expectedConfig, testConfig) + } + + // read file in hcl format + t.Run("toml", func(t *testing.T) { + readFile("./testdata/default.toml") + }) +} diff --git a/internal/cli/server/testdata/default.toml b/internal/cli/server/testdata/default.toml new file mode 100644 index 0000000000..3a6c2f0cb5 --- /dev/null +++ b/internal/cli/server/testdata/default.toml @@ -0,0 +1,193 @@ +chain = "mainnet" +identity = "Polygon-Devs" +verbosity = 3 +log-level = "" +vmdebug = false +datadir = "/var/lib/bor" +ancient = "" +"db.engine" = "leveldb" +keystore = "" +"rpc.batchlimit" = 100 +"rpc.returndatalimit" = 100000 +syncmode = "full" +gcmode = "full" +snapshot = true +"bor.logs" = false +ethstats = "" +devfakeauthor = false + +["eth.requiredblocks"] + +[log] + vmodule = "" + json = false + backtrace = "" + debug = false + +[p2p] + maxpeers = 50 + maxpendpeers = 50 + bind = "0.0.0.0" + port = 30303 + nodiscover = false + nat = "any" + netrestrict = "" + nodekey = "" + nodekeyhex = "" + txarrivalwait = "500ms" + [p2p.discovery] + v4disc = true + v5disc = false + bootnodes = [] + bootnodesv4 = [] + bootnodesv5 = [] + static-nodes = [] + trusted-nodes = [] + dns = [] + +[heimdall] + url = "http://localhost:1317" + "bor.without" = false + grpc-address = "" + "bor.runheimdall" = false + "bor.runheimdallargs" = "" + "bor.useheimdallapp" = false + +[txpool] + locals = [] + nolocals = false + journal = "transactions.rlp" + rejournal = "1h0m0s" + pricelimit = 1 + pricebump = 10 + accountslots = 16 + globalslots = 32768 + accountqueue = 16 + globalqueue = 32768 + lifetime = "3h0m0s" + +[miner] + mine = false + etherbase = "" + extradata = "" + gaslimit = 30000000 + gasprice = "1000000000" + recommit = "2m5s" + commitinterrupt = true + +[jsonrpc] + ipcdisable = false + ipcpath = "" + gascap = 50000000 + evmtimeout = "5s" + txfeecap = 1.0 + allow-unprotected-txs = false + enabledeprecatedpersonal = false + [jsonrpc.http] + enabled = false + port = 8545 + prefix = "" + host = "localhost" + api = ["eth", "net", "web3", "txpool", "bor"] + vhosts = ["localhost"] + corsdomain = ["localhost"] + ep-size = 40 + ep-requesttimeout = "0s" + [jsonrpc.ws] + enabled = false + port = 8546 + prefix = "" + host = "localhost" + api = ["net", "web3"] + origins = ["localhost"] + ep-size = 40 + ep-requesttimeout = "0s" + [jsonrpc.graphql] + enabled = false + port = 0 + prefix = "" + host = "" + vhosts = ["localhost"] + corsdomain = ["localhost"] + ep-size = 0 + ep-requesttimeout = "" + [jsonrpc.auth] + jwtsecret = "" + addr = "localhost" + port = 8551 + vhosts = ["localhost"] + [jsonrpc.timeouts] + read = "10s" + write = "30s" + idle = "2m0s" + +[gpo] + blocks = 20 + percentile = 60 + maxheaderhistory = 1024 + maxblockhistory = 1024 + maxprice = "500000000000" + ignoreprice = "2" + +[telemetry] + metrics = false + expensive = false + prometheus-addr = "127.0.0.1:7071" + opencollector-endpoint = "" + [telemetry.influx] + influxdb = false + endpoint = "" + database = "" + username = "" + password = "" + influxdbv2 = false + token = "" + bucket = "" + organization = "" + [telemetry.influx.tags] + +[cache] + cache = 1024 + gc = 25 + snapshot = 10 + database = 50 + trie = 15 + noprefetch = false + preimages = false + txlookuplimit = 2350000 + triesinmemory = 128 + blocklogs = 32 + timeout = "1h0m0s" + fdlimit = 0 + +[leveldb] + compactiontablesize = 2 + compactiontablesizemultiplier = 1.0 + compactiontotalsize = 10 + compactiontotalsizemultiplier = 10.0 + +[accounts] + unlock = [] + password = "" + allow-insecure-unlock = false + lightkdf = false + disable-bor-wallet = true + +[grpc] + addr = ":3131" + +[developer] + dev = false + period = 0 + gaslimit = 11500000 + +[parallelevm] + enable = true + procs = 8 + +[pprof] + pprof = false + port = 6060 + addr = "127.0.0.1" + memprofilerate = 524288 + blockprofilerate = 0 From f506350ddb98e9568f7856a68b1e2a2100ea4cdf Mon Sep 17 00:00:00 2001 From: Anshal Shukla <53994948+anshalshukla@users.noreply.github.com> Date: Fri, 1 Dec 2023 11:39:58 +0530 Subject: [PATCH 5/6] consensus/bor: handle blockalloc balance changes (#1074) * fix: set balance in blockalloc * chg: don't update balance if not zero * fix: lint * fix logic, add test cases --- consensus/bor/bor.go | 4 ++++ consensus/bor/bor_test.go | 31 ++++++++++++++++++++++++------- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/consensus/bor/bor.go b/consensus/bor/bor.go index 40999f73c4..0314cef8af 100644 --- a/consensus/bor/bor.go +++ b/consensus/bor/bor.go @@ -883,6 +883,10 @@ func (c *Bor) changeContractCodeIfNeeded(headerNumber uint64, state *state.State for addr, account := range allocs { log.Info("change contract code", "address", addr) state.SetCode(addr, account.Code) + + if state.GetBalance(addr).Cmp(big.NewInt(0)) == 0 { + state.SetBalance(addr, account.Balance) + } } } } diff --git a/consensus/bor/bor_test.go b/consensus/bor/bor_test.go index 020289c4dc..9713ce7516 100644 --- a/consensus/bor/bor_test.go +++ b/consensus/bor/bor_test.go @@ -41,6 +41,12 @@ func TestGenesisContractChange(t *testing.T) { "balance": "0x1000", }, }, + "6": map[string]interface{}{ + addr0.Hex(): map[string]interface{}{ + "code": hexutil.Bytes{0x1, 0x4}, + "balance": "0x2000", + }, + }, }, }, } @@ -87,24 +93,35 @@ func TestGenesisContractChange(t *testing.T) { root := genesis.Root() - // code does not change + // code does not change, balance remains 0 root, statedb = addBlock(root, 1) require.Equal(t, statedb.GetCode(addr0), []byte{0x1, 0x1}) + require.Equal(t, statedb.GetBalance(addr0), big.NewInt(0)) - // code changes 1st time + // code changes 1st time, balance remains 0 root, statedb = addBlock(root, 2) require.Equal(t, statedb.GetCode(addr0), []byte{0x1, 0x2}) + require.Equal(t, statedb.GetBalance(addr0), big.NewInt(0)) - // code same as 1st change + // code same as 1st change, balance remains 0 root, statedb = addBlock(root, 3) require.Equal(t, statedb.GetCode(addr0), []byte{0x1, 0x2}) + require.Equal(t, statedb.GetBalance(addr0), big.NewInt(0)) - // code changes 2nd time - _, statedb = addBlock(root, 4) + // code changes 2nd time, balance updates to 4096 + root, statedb = addBlock(root, 4) require.Equal(t, statedb.GetCode(addr0), []byte{0x1, 0x3}) + require.Equal(t, statedb.GetBalance(addr0), big.NewInt(4096)) - // make sure balance change DOES NOT take effect - require.Equal(t, statedb.GetBalance(addr0), big.NewInt(0)) + // code same as 2nd change, balance remains 4096 + root, statedb = addBlock(root, 5) + require.Equal(t, statedb.GetCode(addr0), []byte{0x1, 0x3}) + require.Equal(t, statedb.GetBalance(addr0), big.NewInt(4096)) + + // code changes 3rd time, balance remains 4096 + _, statedb = addBlock(root, 6) + require.Equal(t, statedb.GetCode(addr0), []byte{0x1, 0x4}) + require.Equal(t, statedb.GetBalance(addr0), big.NewInt(4096)) } func TestEncodeSigHeaderJaipur(t *testing.T) { From 3e113ed7dfbb2cbc562006bb5950983f4762a618 Mon Sep 17 00:00:00 2001 From: Anshal Shukla Date: Thu, 28 Mar 2024 17:51:13 +0530 Subject: [PATCH 6/6] fix: failure in milestones vote on hash --- eth/bor_api_backend.go | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/eth/bor_api_backend.go b/eth/bor_api_backend.go index dbc6844d8a..9f909caa8e 100644 --- a/eth/bor_api_backend.go +++ b/eth/bor_api_backend.go @@ -83,21 +83,6 @@ func (b *EthAPIBackend) GetVoteOnHash(ctx context.Context, starBlockNr uint64, e return false, fmt.Errorf("Hash mismatch: localChainHash %s, milestoneHash %s", localEndBlockHash, hash) } - ethHandler := (*ethHandler)(b.eth.handler) - - bor, ok := ethHandler.chain.Engine().(*bor.Bor) - - if !ok { - return false, fmt.Errorf("Bor not available") - } - - err = bor.HeimdallClient.FetchMilestoneID(ctx, milestoneId) - - if err != nil { - downloader.UnlockMutex(false, "", endBlockNr, common.Hash{}) - return false, fmt.Errorf("Milestone ID doesn't exist in Heimdall") - } - downloader.UnlockMutex(true, milestoneId, endBlockNr, localEndBlock.Hash()) return true, nil