diff --git a/.golangci.yml b/.golangci.yml index 72955396a8..924e084431 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -6,8 +6,6 @@ run: # default is true. Enables skipping of directories: # vendor$, third_party$, testdata$, examples$, Godeps$, builtin$ skip-dirs-use-default: true - skip-files: - - core/genesis_alloc.go linters: disable-all: true @@ -44,6 +42,8 @@ linters-settings: min-occurrences: 6 # minimum number of occurrences issues: + exclude-files: + - core/genesis_alloc.go exclude-rules: - path: crypto/bn256/cloudflare/optate.go linters: @@ -64,4 +64,4 @@ issues: - 'SA1029: should not use built-in type string as key for value' - 'SA1019: "io/ioutil" has been deprecated since Go 1.19: As of Go 1.16, the same functionality is now provided by package [io] or package [os], and those implementations should be preferred in new code. See the specific function documentation for details' - 'SA1019: grpc.WithInsecure is deprecated: use WithTransportCredentials and insecure.NewCredentials() instead. Will be supported throughout 1.x' - - "SA1019: rand.Read has been deprecated since Go 1.20 because it shouldn't be used: For almost all use cases, crypto/rand.Read is more appropriate" + - "SA1019: rand.Read has been deprecated since Go 1.20 because it shouldn't be used: For almost all use cases, crypto/rand.Read is more appropriate" \ No newline at end of file diff --git a/Makefile b/Makefile index cdd0822c15..f074cddc32 100644 --- a/Makefile +++ b/Makefile @@ -80,7 +80,7 @@ lint: lintci-deps: rm -f ./build/bin/golangci-lint - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ./build/bin v1.53.3 + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ./build/bin v1.57.2 goimports: goimports -local "$(PACKAGE)" -w . diff --git a/accounts/abi/bind/util_test.go b/accounts/abi/bind/util_test.go index a35e56a6a8..f58eb9ae84 100644 --- a/accounts/abi/bind/util_test.go +++ b/accounts/abi/bind/util_test.go @@ -29,6 +29,7 @@ import ( "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/params" ) var testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") @@ -64,7 +65,7 @@ func TestWaitDeployed(t *testing.T) { // Create the transaction head, _ := backend.HeaderByNumber(context.Background(), nil) // Should be child's, good enough - gasPrice := new(big.Int).Add(head.BaseFee, big.NewInt(1)) + gasPrice := new(big.Int).Add(head.BaseFee, big.NewInt(params.GWei)) tx := types.NewContractCreation(0, big.NewInt(0), test.gas, gasPrice, common.FromHex(test.code)) tx, _ = types.SignTx(tx, types.HomesteadSigner{}, testKey) diff --git a/audit/audit-feature-milestones.pdf b/audit/audit-feature-milestones.pdf new file mode 100644 index 0000000000..7c53ea88f8 Binary files /dev/null and b/audit/audit-feature-milestones.pdf differ 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) { diff --git a/consensus/bor/valset/validator_set.go b/consensus/bor/valset/validator_set.go index da187ddf9d..b301470e56 100644 --- a/consensus/bor/valset/validator_set.go +++ b/consensus/bor/valset/validator_set.go @@ -435,7 +435,7 @@ func verifyUpdates(updates []*Validator, vals *ValidatorSet) (updatedTotalVoting _, val := vals.GetByAddress(address) if val == nil { - // New validator, add its voting power the the total. + // New validator, add its voting power the total. updatedTotalVotingPower += valUpdate.VotingPower numNewValidators++ } else { diff --git a/core/blockstm/mvhashmap_test.go b/core/blockstm/mvhashmap_test.go index 7ed728426c..c099165f1a 100644 --- a/core/blockstm/mvhashmap_test.go +++ b/core/blockstm/mvhashmap_test.go @@ -158,7 +158,7 @@ func TestMVHashMapBasics(t *testing.T) { mvh.Write(ap1, Version{10, 1}, valueFor(10, 1)) res = mvh.Read(ap1, 9) - require.Equal(t, -1, res.depIdx, "reads that should go the the DB return dependency -1") + require.Equal(t, -1, res.depIdx, "reads that should go the DB return dependency -1") res = mvh.Read(ap1, 10) require.Equal(t, -1, res.depIdx, "Read returns entries from smaller txns, not txn 10") diff --git a/core/rawdb/accessors_chain.go b/core/rawdb/accessors_chain.go index aeed8da55c..25b7406e4c 100644 --- a/core/rawdb/accessors_chain.go +++ b/core/rawdb/accessors_chain.go @@ -362,8 +362,8 @@ func ReadHeaderRange(db ethdb.Reader, number uint64, count uint64) []rlp.RawValu if count == 0 { return rlpHeaders } - // read remaining from ancients - data, err := db.AncientRange(ChainFreezerHeaderTable, i+1-count, count, 0) + // read remaining from ancients, cap at 2M + data, err := db.AncientRange(ChainFreezerHeaderTable, i+1-count, count, 2*1024*1024) if err != nil { log.Error("Failed to read headers from freezer", "err", err) return rlpHeaders diff --git a/core/txpool/legacypool/legacypool.go b/core/txpool/legacypool/legacypool.go index 6794f29d9a..a00f79dff3 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 @@ -617,7 +618,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<= remoteHeight-d.maxValidationThreshold { + log.Info("Remote peer didn't respond", "id", p.id, "local", localHeight, "remote", remoteHeight, "err", err) + return 0, err + } + + log.Info("Remote peer didn't respond but is far ahead, skipping validation", "id", p.id, "local", localHeight, "remote", remoteHeight, "err", err) + } + } + p.log.Debug("Looking for common ancestor", "local", localHeight, "remote", remoteHeight) // Recap floor value for binary search diff --git a/eth/downloader/downloader_test.go b/eth/downloader/downloader_test.go index b248c860ec..e1ecd011e3 100644 --- a/eth/downloader/downloader_test.go +++ b/eth/downloader/downloader_test.go @@ -1649,14 +1649,42 @@ func TestFakedSyncProgress67NoRemoteCheckpoint(t *testing.T) { chainA := testChainForkLightA.blocks tester.newPeer("light", protocol, chainA[1:]) + // Set the max validation threshold equal to chain length to enforce validation + tester.downloader.maxValidationThreshold = uint64(len(chainA) - 1) + // Synchronise with the peer and make sure all blocks were retrieved // Should fail in first attempt - if err := tester.sync("light", nil, mode); err != nil { - assert.Equal(t, whitelist.ErrNoRemote, err, "failed synchronisation") - } + err := tester.sync("light", nil, mode) + assert.Equal(t, whitelist.ErrNoRemote, err, "failed synchronisation") // Try syncing again, should succeed if err := tester.sync("light", nil, mode); err != nil { t.Fatal("succeeded attacker synchronisation") } } + +// TestFakedSyncProgress67BypassWhitelistValidation tests if peer validation +// via whitelist is bypassed when remote peer is far away or not +func TestFakedSyncProgress67BypassWhitelistValidation(t *testing.T) { + protocol := uint(eth.ETH67) + mode := FullSync + + tester := newTester(t) + validate := func(count int) (bool, error) { + return false, whitelist.ErrNoRemote + } + + tester.downloader.ChainValidator = newWhitelistFake(validate) + + defer tester.terminate() + + // 1223 length chain + chainA := testChainBase.blocks + tester.newPeer("light", protocol, chainA[1:]) + + // Although the validate function above returns an error (which says that + // remote peer doesn't have that block), sync will go through as the chain + // import length is 1223 which is more than the default threshold of 1024 + err := tester.sync("light", nil, mode) + assert.NoError(t, err, "failed synchronisation") +} diff --git a/eth/handler_eth_test.go b/eth/handler_eth_test.go index 6e36cb2a56..c44b4c9a33 100644 --- a/eth/handler_eth_test.go +++ b/eth/handler_eth_test.go @@ -488,7 +488,7 @@ func testBroadcastBlock(t *testing.T, peers, bcasts int) { ) for i, sink := range sinks { - sink := sink // Closure for gorotuine below + sink := sink // Closure for goroutine below sourcePipe, sinkPipe := p2p.MsgPipe() defer sourcePipe.Close() diff --git a/ethdb/pebble/pebble.go b/ethdb/pebble/pebble.go index 50612cee9a..522299c980 100644 --- a/ethdb/pebble/pebble.go +++ b/ethdb/pebble/pebble.go @@ -25,7 +25,6 @@ import ( "sync/atomic" "time" - "github.com/cockroachdb/errors" "github.com/cockroachdb/pebble" "github.com/cockroachdb/pebble/bloom" @@ -136,7 +135,7 @@ func (l panicLogger) Errorf(format string, args ...interface{}) { } func (l panicLogger) Fatalf(format string, args ...interface{}) { - panic(errors.Errorf("fatal: "+format, args...)) + panic(fmt.Errorf("fatal: "+format, args...)) } // New returns a wrapped pebble DB object. The namespace is the prefix that the @@ -628,10 +627,7 @@ func (b *batch) Replay(w ethdb.KeyValueWriter) error { for { kind, k, v, ok, err := reader.Next() - if err != nil { - return err - } - if !ok { + if !ok || err != nil { break } // The (k,v) slices might be overwritten if the batch is reset/reused, @@ -650,9 +646,12 @@ func (b *batch) Replay(w ethdb.KeyValueWriter) error { // pebbleIterator is a wrapper of underlying iterator in storage engine. // The purpose of this structure is to implement the missing APIs. +// +// The pebble iterator is not thread-safe. type pebbleIterator struct { - iter *pebble.Iterator - moved bool + iter *pebble.Iterator + moved bool + released bool } // NewIterator creates a binary-alphabetical iterator over a subset @@ -664,8 +663,7 @@ func (d *Database) NewIterator(prefix []byte, start []byte) ethdb.Iterator { UpperBound: upperBound(prefix), }) iter.First() - - return &pebbleIterator{iter: iter, moved: true} + return &pebbleIterator{iter: iter, moved: true, released: false} } // Next moves the iterator to the next key/value pair. It returns whether the @@ -701,4 +699,9 @@ func (iter *pebbleIterator) Value() []byte { // Release releases associated resources. Release should always succeed and can // be called multiple times without causing error. -func (iter *pebbleIterator) Release() { iter.iter.Close() } +func (iter *pebbleIterator) Release() { + if !iter.released { + iter.iter.Close() + iter.released = true + } +} diff --git a/go.mod b/go.mod index 2a5c721e53..3f7497fdf9 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,6 @@ require ( github.com/btcsuite/btcd/btcec/v2 v2.3.2 github.com/cespare/cp v1.1.1 github.com/cloudflare/cloudflare-go v0.89.0 - github.com/cockroachdb/errors v1.11.1 github.com/cockroachdb/pebble v1.1.0 github.com/consensys/gnark-crypto v0.12.1 github.com/cosmos/cosmos-sdk v0.50.4 @@ -124,8 +123,10 @@ require ( github.com/beorn7/perks v1.0.1 // indirect github.com/bits-and-blooms/bitset v1.7.0 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/cockroachdb/errors v1.11.1 // indirect github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect github.com/cockroachdb/redact v1.1.5 // indirect + github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect github.com/consensys/bavard v0.1.13 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect github.com/crate-crypto/go-ipa v0.0.0-20230905211650-63ccabc1a949 // indirect @@ -133,10 +134,10 @@ require ( github.com/dlclark/regexp2 v1.7.0 // indirect github.com/garslo/gogen v0.0.0-20170306192744-1d203ffc1f61 // indirect github.com/getsentry/sentry-go v0.18.0 // indirect - github.com/go-ole/go-ole v1.2.6 // indirect + github.com/go-ole/go-ole v1.3.0 // indirect github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect github.com/gogo/protobuf v1.3.2 // indirect - github.com/google/go-cmp v0.5.9 // indirect + github.com/google/go-querystring v1.1.0 // indirect github.com/google/pprof v0.0.0-20230207041349-798e818bf904 // indirect github.com/influxdata/line-protocol v0.0.0-20210311194329-9aa0e372d097 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect @@ -194,7 +195,6 @@ require ( github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce // indirect github.com/cbergoon/merkletree v0.2.0 // indirect github.com/cenkalti/backoff/v4 v4.2.1 // indirect - github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect github.com/cosmos/go-bip39 v1.0.0 // indirect github.com/cosmos/ledger-cosmos-go v0.13.0 // indirect github.com/etcd-io/bbolt v1.3.3 // indirect @@ -208,7 +208,7 @@ require ( github.com/goccy/go-json v0.10.2 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/gomodule/redigo v2.0.0+incompatible // indirect - github.com/google/go-querystring v1.1.0 // indirect + github.com/google/go-cmp v0.5.9 // indirect github.com/google/s2a-go v0.1.4 // indirect github.com/googleapis/gax-go/v2 v2.11.0 // indirect github.com/gorilla/mux v1.8.0 // indirect diff --git a/go.sum b/go.sum index 324d6a83b5..3e7e59986e 100644 --- a/go.sum +++ b/go.sum @@ -1214,8 +1214,9 @@ github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab/go.mod h1:/P9AEU963A2AYjv4d1V5eVL1CQbEJq6aCNHDDjibzu8= github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= -github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= +github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE= +github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78= github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= github.com/go-pdf/fpdf v0.5.0/go.mod h1:HzcnA+A23uwogo0tp9yU+l3V+KXhiESpt1PMayhOh5M= diff --git a/internal/cli/dumpconfig.go b/internal/cli/dumpconfig.go index f01adef628..13ef57c087 100644 --- a/internal/cli/dumpconfig.go +++ b/internal/cli/dumpconfig.go @@ -28,7 +28,7 @@ func (p *DumpconfigCommand) MarkDown() string { func (c *DumpconfigCommand) Help() string { return `Usage: bor dumpconfig - This command will will export the user provided flags into a configuration file` + This command will export the user provided flags into a configuration file` } // Synopsis implements the cli.Command interface 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 diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 2d988ac94e..8acc6a39b3 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1092,7 +1092,13 @@ func (s *BlockChainAPI) GetBlockReceipts(ctx context.Context, blockNrOrHash rpc. result := make([]map[string]interface{}, len(receipts)) for i, receipt := range receipts { - result[i] = marshalReceipt(receipt, block.Hash(), block.NumberU64(), signer, txs[i], i) + result[i] = marshalReceipt(receipt, block.Hash(), block.NumberU64(), signer, txs[i], i, false) + } + + stateSyncReceipt := rawdb.ReadBorReceipt(s.b.ChainDb(), block.Hash(), block.NumberU64(), s.b.ChainConfig()) + if stateSyncReceipt != nil { + tx, _, _, _ := rawdb.ReadBorTransaction(s.b.ChainDb(), stateSyncReceipt.TxHash) + result = append(result, marshalReceipt(stateSyncReceipt, block.Hash(), block.NumberU64(), signer, tx, len(result), true)) } return result, nil @@ -2225,17 +2231,24 @@ func (s *TransactionAPI) GetTransactionReceipt(ctx context.Context, hash common. // Derive the sender. signer := types.MakeSigner(s.b.ChainConfig(), header.Number, header.Time) - return marshalReceipt(receipt, blockHash, blockNumber, signer, tx, int(index)), nil + return marshalReceipt(receipt, blockHash, blockNumber, signer, tx, int(index), borTx), nil } // marshalReceipt marshals a transaction receipt into a JSON object. -func marshalReceipt(receipt *types.Receipt, blockHash common.Hash, blockNumber uint64, signer types.Signer, tx *types.Transaction, txIndex int) map[string]interface{} { +func marshalReceipt(receipt *types.Receipt, blockHash common.Hash, blockNumber uint64, signer types.Signer, tx *types.Transaction, txIndex int, borTx bool) map[string]interface{} { from, _ := types.Sender(signer, tx) + txHash := common.Hash{} + if borTx { + txHash = types.GetDerivedBorTxHash(types.BorReceiptKey(blockNumber, blockHash)) + } else { + txHash = tx.Hash() + } + fields := map[string]interface{}{ "blockHash": blockHash, "blockNumber": hexutil.Uint64(blockNumber), - "transactionHash": tx.Hash(), + "transactionHash": txHash, "transactionIndex": hexutil.Uint64(txIndex), "from": from, "to": tx.To(), diff --git a/internal/ethapi/testdata/eth_getTransactionReceipt-state-sync-tx.json b/internal/ethapi/testdata/eth_getTransactionReceipt-state-sync-tx.json new file mode 100644 index 0000000000..2fb229ce2f --- /dev/null +++ b/internal/ethapi/testdata/eth_getTransactionReceipt-state-sync-tx.json @@ -0,0 +1,17 @@ +{ + "blockHash": "0x4d780246cde52e535f40603d47af8fa1aea807dd3065e1acd97127bea0922b3e", + "blockNumber": "0x6", + "contractAddress": null, + "cumulativeGasUsed": "0xe01c", + "effectiveGasPrice": "0x1ecb3fb4", + "from": "0x703c4b2bd70c169f5717101caee543299fc946c7", + "gasUsed": "0xe01c", + "logs": [], + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "status": "0x1", + "to": null, + "transactionHash": "0xb5a1148819cfdfff9bfe70035524fec940eb735d89b76960b97751d01ae2a9f2", + "transactionIndex": "0x0", + "type": "0x1" + } + \ No newline at end of file diff --git a/internal/jsre/deps/web3.js b/internal/jsre/deps/web3.js index 70bd4b1508..8ca32889c5 100644 --- a/internal/jsre/deps/web3.js +++ b/internal/jsre/deps/web3.js @@ -1405,7 +1405,7 @@ var SolidityType = function (config) { * @return {Bool} true if type match this SolidityType, otherwise false */ SolidityType.prototype.isType = function (name) { - throw "this method should be overrwritten for type " + name; + throw "this method should be overwritten for type " + name; }; /** diff --git a/miner/miner.go b/miner/miner.go index cfc85ebfcb..03fa21edbf 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -219,6 +219,11 @@ func (miner *Miner) SetExtra(extra []byte) error { return nil } +func (miner *Miner) SetGasTip(tip *big.Int) error { + miner.worker.setGasTip(tip) + return nil +} + // SetRecommitInterval sets the interval for sealing work resubmitting. func (miner *Miner) SetRecommitInterval(interval time.Duration) { miner.worker.setRecommitInterval(interval) diff --git a/miner/ordering.go b/miner/ordering.go index 9777633510..828d53d241 100644 --- a/miner/ordering.go +++ b/miner/ordering.go @@ -119,11 +119,11 @@ func newTransactionsByPriceAndNonce(signer types.Signer, txs map[common.Address] } // Peek returns the next transaction by price. -func (t *transactionsByPriceAndNonce) Peek() *txpool.LazyTransaction { +func (t *transactionsByPriceAndNonce) Peek() (*txpool.LazyTransaction, *big.Int) { if len(t.heads) == 0 { - return nil + return nil, nil } - return t.heads[0].tx + return t.heads[0].tx, t.heads[0].fees } // Shift replaces the current best head with the next one from the same account. diff --git a/miner/ordering_test.go b/miner/ordering_test.go index 59d478274d..c2f08328db 100644 --- a/miner/ordering_test.go +++ b/miner/ordering_test.go @@ -102,7 +102,7 @@ func testTransactionPriceNonceSort(t *testing.T, baseFee *big.Int) { txset := newTransactionsByPriceAndNonce(signer, groups, baseFee) txs := types.Transactions{} - for tx := txset.Peek(); tx != nil; tx = txset.Peek() { + for tx, _ := txset.Peek(); tx != nil; tx, _ = txset.Peek() { txs = append(txs, tx.Tx) txset.Shift() } @@ -167,7 +167,7 @@ func TestTransactionTimeSort(t *testing.T) { txset := newTransactionsByPriceAndNonce(signer, groups, nil) txs := types.Transactions{} - for tx := txset.Peek(); tx != nil; tx = txset.Peek() { + for tx, _ := txset.Peek(); tx != nil; tx, _ = txset.Peek() { txs = append(txs, tx.Tx) txset.Shift() } diff --git a/miner/test_backend.go b/miner/test_backend.go index b2fa96b059..03447f446f 100644 --- a/miner/test_backend.go +++ b/miner/test_backend.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "math/big" "os" "sync" "sync/atomic" @@ -175,7 +176,7 @@ func (w *worker) mainLoopWithDelay(ctx context.Context, delay uint, opcodeDelay } txset := newTransactionsByPriceAndNonce(w.current.signer, txs, w.current.header.BaseFee) tcount := w.current.tcount - w.commitTransactions(w.current, txset, nil, context.Background()) + w.commitTransactions(w.current, txset, nil, new(big.Int), context.Background()) // Only update the snapshot if any new transactons were added // to the pending block @@ -587,7 +588,7 @@ mainloop: break } // Retrieve the next transaction and abort if all done. - ltx := txs.Peek() + ltx, _ := txs.Peek() if ltx == nil { breakCause = "all transactions has been included" break diff --git a/miner/worker.go b/miner/worker.go index ae96bc721e..b134f83069 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -237,6 +237,7 @@ type worker struct { mu sync.RWMutex // The lock used to protect the coinbase and extra fields coinbase common.Address extra []byte + tip *big.Int // Minimum tip needed for non-local transaction to include them pendingMu sync.RWMutex pendingTasks map[common.Hash]*task @@ -295,6 +296,7 @@ func newWorker(config *Config, chainConfig *params.ChainConfig, engine consensus isLocalBlock: isLocalBlock, coinbase: config.Etherbase, extra: config.ExtraData, + tip: config.GasPrice, pendingTasks: make(map[common.Hash]*task), txsCh: make(chan core.NewTxsEvent, txChanSize), chainHeadCh: make(chan core.ChainHeadEvent, chainHeadChanSize), @@ -395,6 +397,13 @@ func (w *worker) setExtra(extra []byte) { w.extra = extra } +// setGasTip sets the minimum miner tip needed to include a non-local transaction. +func (w *worker) setGasTip(tip *big.Int) { + w.mu.Lock() + defer w.mu.Unlock() + w.tip = tip +} + // setRecommitInterval updates the interval for miner sealing work recommitting. func (w *worker) setRecommitInterval(interval time.Duration) { select { @@ -648,7 +657,7 @@ func (w *worker) mainLoop(ctx context.Context) { } txset := newTransactionsByPriceAndNonce(w.current.signer, txs, w.current.header.BaseFee) tcount := w.current.tcount - w.commitTransactions(w.current, txset, nil, context.Background()) + w.commitTransactions(w.current, txset, nil, new(big.Int), context.Background()) // Only update the snapshot if any new transactons were added // to the pending block @@ -908,7 +917,7 @@ func (w *worker) commitTransaction(env *environment, tx *types.Transaction, inte return receipt.Logs, nil } -func (w *worker) commitTransactions(env *environment, txs *transactionsByPriceAndNonce, interrupt *atomic.Int32, interruptCtx context.Context) error { +func (w *worker) commitTransactions(env *environment, txs *transactionsByPriceAndNonce, interrupt *atomic.Int32, minTip *big.Int, interruptCtx context.Context) error { gasLimit := env.header.GasLimit if env.gasPool == nil { env.gasPool = new(core.GasPool).AddGas(gasLimit) @@ -921,6 +930,7 @@ func (w *worker) commitTransactions(env *environment, txs *transactionsByPriceAn chDeps := make(chan blockstm.TxDep) var depsWg sync.WaitGroup + var once sync.Once EnableMVHashMap := w.chainConfig.IsCancun(env.header.Number) @@ -930,6 +940,11 @@ func (w *worker) commitTransactions(env *environment, txs *transactionsByPriceAn chDeps = make(chan blockstm.TxDep) + // Make sure we safely close the channel in case of interrupt + defer once.Do(func() { + close(chDeps) + }) + depsWg.Add(1) go func(chDeps chan blockstm.TxDep) { @@ -990,7 +1005,7 @@ mainloop: break } // Retrieve the next transaction and abort if all done. - ltx := txs.Peek() + ltx, tip := txs.Peek() if ltx == nil { breakCause = "all transactions has been included" break @@ -1006,6 +1021,11 @@ mainloop: txs.Pop() continue } + // If we don't receive enough tip for the next transaction, skip the account + if tip.Cmp(minTip) < 0 { + log.Trace("Not enough tip for transaction", "hash", ltx.Hash, "tip", tip, "needed", minTip) + break // If the next-best is too low, surely no better will be available + } // Transaction seems to fit, pull it up from the pool tx := ltx.Resolve() if tx == nil { @@ -1109,7 +1129,9 @@ mainloop: // nolint:nestif if EnableMVHashMap && w.IsRunning() { - close(chDeps) + once.Do(func() { + close(chDeps) + }) depsWg.Wait() var blockExtraData types.BlockExtraData @@ -1461,6 +1483,10 @@ func (w *worker) fillTransactions(ctx context.Context, interrupt *atomic.Int32, err error ) + w.mu.RLock() + tip := w.tip + w.mu.RUnlock() + if len(localTxs) > 0 { var txs *transactionsByPriceAndNonce @@ -1479,7 +1505,7 @@ func (w *worker) fillTransactions(ctx context.Context, interrupt *atomic.Int32, }) tracing.Exec(ctx, "", "worker.LocalCommitTransactions", func(ctx context.Context, span trace.Span) { - err = w.commitTransactions(env, txs, interrupt, interruptCtx) + err = w.commitTransactions(env, txs, interrupt, new(big.Int), interruptCtx) }) if err != nil { @@ -1507,7 +1533,7 @@ func (w *worker) fillTransactions(ctx context.Context, interrupt *atomic.Int32, }) tracing.Exec(ctx, "", "worker.RemoteCommitTransactions", func(ctx context.Context, span trace.Span) { - err = w.commitTransactions(env, txs, interrupt, interruptCtx) + err = w.commitTransactions(env, txs, interrupt, tip, interruptCtx) }) if err != nil { diff --git a/packaging/templates/package_scripts/control b/packaging/templates/package_scripts/control index 2af0cb0885..f7fe99f821 100644 --- a/packaging/templates/package_scripts/control +++ b/packaging/templates/package_scripts/control @@ -1,5 +1,5 @@ Source: bor -Version: 1.3.0 +Version: 1.3.2 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.arm64 b/packaging/templates/package_scripts/control.arm64 index 5d941a70f3..7a249535c1 100644 --- a/packaging/templates/package_scripts/control.arm64 +++ b/packaging/templates/package_scripts/control.arm64 @@ -1,5 +1,5 @@ Source: bor -Version: 1.3.0 +Version: 1.3.2 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.profile.amd64 b/packaging/templates/package_scripts/control.profile.amd64 index 6f655622d6..7583138025 100644 --- a/packaging/templates/package_scripts/control.profile.amd64 +++ b/packaging/templates/package_scripts/control.profile.amd64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.3.0 +Version: 1.3.2 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.profile.arm64 b/packaging/templates/package_scripts/control.profile.arm64 index 0f7f1afe35..89facfc4ca 100644 --- a/packaging/templates/package_scripts/control.profile.arm64 +++ b/packaging/templates/package_scripts/control.profile.arm64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.3.0 +Version: 1.3.2 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.validator b/packaging/templates/package_scripts/control.validator index b4fe3780f9..823b9ed742 100644 --- a/packaging/templates/package_scripts/control.validator +++ b/packaging/templates/package_scripts/control.validator @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.3.0 +Version: 1.3.2 Section: develop Priority: standard Maintainer: Polygon diff --git a/packaging/templates/package_scripts/control.validator.arm64 b/packaging/templates/package_scripts/control.validator.arm64 index 0f7f1afe35..89facfc4ca 100644 --- a/packaging/templates/package_scripts/control.validator.arm64 +++ b/packaging/templates/package_scripts/control.validator.arm64 @@ -1,5 +1,5 @@ Source: bor-profile -Version: 1.3.0 +Version: 1.3.2 Section: develop Priority: standard Maintainer: Polygon 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 { diff --git a/params/version.go b/params/version.go index ea681616c6..35206e280e 100644 --- a/params/version.go +++ b/params/version.go @@ -23,7 +23,7 @@ import ( const ( VersionMajor = 1 // Major version component of the current release VersionMinor = 3 // Minor version component of the current release - VersionPatch = 0 // Patch version component of the current release + VersionPatch = 2 // Patch version component of the current release VersionMeta = "" // Version metadata to append to the version string ) diff --git a/rlp/unsafe.go b/rlp/unsafe.go index d5b0d29a09..10868caaf2 100644 --- a/rlp/unsafe.go +++ b/rlp/unsafe.go @@ -26,11 +26,5 @@ import ( // byteArrayBytes returns a slice of the byte array v. func byteArrayBytes(v reflect.Value, length int) []byte { - var s []byte - hdr := (*reflect.SliceHeader)(unsafe.Pointer(&s)) - hdr.Data = v.UnsafeAddr() - hdr.Cap = length - hdr.Len = length - - return s + return unsafe.Slice((*byte)(unsafe.Pointer(v.UnsafeAddr())), length) } diff --git a/tests/bor/bor_api_test.go b/tests/bor/bor_api_test.go index cd4119c0e9..8d314193a7 100644 --- a/tests/bor/bor_api_test.go +++ b/tests/bor/bor_api_test.go @@ -98,6 +98,15 @@ func testGetTransactionReceiptsByBlock(t *testing.T, publicBlockchainAPI *ethapi assert.Equal(t, 2, len(receiptsOut)) assert.True(t, areDifferentHashes(receiptsOut)) + // check 5: Tx hash for state sync txn + block, err := publicBlockchainAPI.GetBlockByNumber(context.Background(), rpc.BlockNumber(4), false) + assert.Nil(t, err) + blockHash := block["hash"].(common.Hash) + txHash := types.GetDerivedBorTxHash(types.BorReceiptKey(4, blockHash)) + // Compare tx hash from GetTransactionReceiptsByBlock with hash computed above + txReceipts, err := publicBlockchainAPI.GetTransactionReceiptsByBlock(context.Background(), rpc.BlockNumberOrHashWithNumber(4)) + assert.Nil(t, err) + assert.Equal(t, txHash, txReceipts[1]["transactionHash"].(common.Hash)) } // Test for GetTransactionByBlockNumberAndIndex @@ -122,7 +131,7 @@ func testGetTransactionByBlockNumberAndIndex(t *testing.T, publicTransactionPool tx = publicTransactionPoolAPI.GetTransactionByBlockNumberAndIndex(context.Background(), rpc.BlockNumber(4), 0) assert.Equal(t, common.HexToAddress("0x1000"), *tx.To) - // check 5 : Normal Transaction + // check 5 : State Sync Transaction tx = publicTransactionPoolAPI.GetTransactionByBlockNumberAndIndex(context.Background(), rpc.BlockNumber(4), 1) assert.Equal(t, common.HexToAddress("0x0"), *tx.To) }