Merge branch 'develop' into develop_lock_v1.3.3

This commit is contained in:
lx 2023-11-30 10:14:39 +08:00 committed by GitHub
commit 20dcaabfdc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 363 additions and 134 deletions

@ -49,6 +49,7 @@ jobs:
CGO_CFLAGS_ALLOW: "-O -D__BLST_PORTABLE__" CGO_CFLAGS_ALLOW: "-O -D__BLST_PORTABLE__"
ANDROID_HOME: "" # Skip android test ANDROID_HOME: "" # Skip android test
run: | run: |
git submodule update --init --depth 1 --recursive
go mod download go mod download
make test make test

@ -150,14 +150,27 @@ unzip testnet.zip
Download latest chaindata snapshot from [here](https://github.com/bnb-chain/bsc-snapshots). Follow the guide to structure your files. Download latest chaindata snapshot from [here](https://github.com/bnb-chain/bsc-snapshots). Follow the guide to structure your files.
Note: if you can not download the chaindata snapshot and want to sync from genesis, you have to generate the genesis block first, you have already get the genesis.json in Step 2. Note: if you can not download the chaindata snapshot and want to sync from genesis, you have to generate the genesis block first, you have already get the genesis.json in Step 2.
So just run: `geth --datadir <datadir> init ./genesis.json` So just run:
``` shell
## It will init genesis with Hash-Base Storage Scheme by default.
geth --datadir <datadir> init ./genesis.json
## It will init genesis with Path-Base Storage Scheme.
geth --datadir <datadir> --state.scheme path init ./genesis.json
```
#### 4. Start a full node #### 4. Start a full node
```shell ```shell
./geth --config ./config.toml --datadir ./node --cache 8000 --rpc.allow-unprotected-txs --history.transactions 0 ./geth --config ./config.toml --datadir ./node --cache 8000 --rpc.allow-unprotected-txs --history.transactions 0
## It is recommand to run fullnode with `--tries-verify-mode none` if you want high performance and care little about state consistency ## It is recommand to run fullnode with `--tries-verify-mode none` if you want high performance and care little about state consistency
## It will run with Hash-Base Storage Scheme by default
./geth --config ./config.toml --datadir ./node --cache 8000 --rpc.allow-unprotected-txs --history.transactions 0 --tries-verify-mode none ./geth --config ./config.toml --datadir ./node --cache 8000 --rpc.allow-unprotected-txs --history.transactions 0 --tries-verify-mode none
## It runs fullnode with Path-Base Storage Scheme.
## It will enable inline state prune, keeping the latest 90000 blocks' history state by default.
./geth --config ./config.toml --datadir ./node --cache 8000 --rpc.allow-unprotected-txs --history.transactions 0 --tries-verify-mode none --state.scheme path
```
#### 5. Monitor node status #### 5. Monitor node status
Monitor the log from **./node/bsc.log** by default. When the node has started syncing, should be able to see the following output: Monitor the log from **./node/bsc.log** by default. When the node has started syncing, should be able to see the following output:

@ -21,6 +21,8 @@ import (
"fmt" "fmt"
"math/big" "math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
) )
@ -45,5 +47,45 @@ func VerifyEIP1559Header(config *params.ChainConfig, parent, header *types.Heade
// CalcBaseFee calculates the basefee of the header. // CalcBaseFee calculates the basefee of the header.
func CalcBaseFee(config *params.ChainConfig, parent *types.Header) *big.Int { func CalcBaseFee(config *params.ChainConfig, parent *types.Header) *big.Int {
return new(big.Int).SetUint64(params.InitialBaseFee) if config.Parlia != nil {
return new(big.Int).SetUint64(params.InitialBaseFee)
}
// If the current block is the first EIP-1559 block, return the InitialBaseFee.
if !config.IsLondon(parent.Number) {
return new(big.Int).SetUint64(params.InitialBaseFee)
}
parentGasTarget := parent.GasLimit / config.ElasticityMultiplier()
// If the parent gasUsed is the same as the target, the baseFee remains unchanged.
if parent.GasUsed == parentGasTarget {
return new(big.Int).Set(parent.BaseFee)
}
var (
num = new(big.Int)
denom = new(big.Int)
)
if parent.GasUsed > parentGasTarget {
// If the parent block used more gas than its target, the baseFee should increase.
// max(1, parentBaseFee * gasUsedDelta / parentGasTarget / baseFeeChangeDenominator)
num.SetUint64(parent.GasUsed - parentGasTarget)
num.Mul(num, parent.BaseFee)
num.Div(num, denom.SetUint64(parentGasTarget))
num.Div(num, denom.SetUint64(config.BaseFeeChangeDenominator()))
baseFeeDelta := math.BigMax(num, common.Big1)
return num.Add(parent.BaseFee, baseFeeDelta)
} else {
// Otherwise if the parent block used less gas than its target, the baseFee should decrease.
// max(0, parentBaseFee * gasUsedDelta / parentGasTarget / baseFeeChangeDenominator)
num.SetUint64(parentGasTarget - parent.GasUsed)
num.Mul(num, parent.BaseFee)
num.Div(num, denom.SetUint64(parentGasTarget))
num.Div(num, denom.SetUint64(config.BaseFeeChangeDenominator()))
baseFee := num.Sub(parent.BaseFee, num)
return math.BigMax(baseFee, common.Big0)
}
} }

@ -51,6 +51,11 @@ func copyConfig(original *params.ChainConfig) *params.ChainConfig {
func config() *params.ChainConfig { func config() *params.ChainConfig {
config := copyConfig(params.TestChainConfig) config := copyConfig(params.TestChainConfig)
config.Ethash = nil
config.Parlia = &params.ParliaConfig{
Period: 3,
Epoch: 200,
}
config.LondonBlock = big.NewInt(5) config.LondonBlock = big.NewInt(5)
return config return config
} }

@ -48,7 +48,7 @@ import (
) )
const ( const (
inMemorySnapshots = 128 // Number of recent snapshots to keep in memory inMemorySnapshots = 256 // Number of recent snapshots to keep in memory
inMemorySignatures = 4096 // Number of recent block signatures to keep in memory inMemorySignatures = 4096 // Number of recent block signatures to keep in memory
checkpointInterval = 1024 // Number of blocks after which to save the snapshot to the database checkpointInterval = 1024 // Number of blocks after which to save the snapshot to the database
@ -680,7 +680,7 @@ func (p *Parlia) snapshot(chain consensus.ChainHeaderReader, number uint64, hash
// If we're at the genesis, snapshot the initial state. Alternatively if we have // If we're at the genesis, snapshot the initial state. Alternatively if we have
// piled up more headers than allowed to be reorged (chain reinit from a freezer), // piled up more headers than allowed to be reorged (chain reinit from a freezer),
// consider the checkpoint trusted and snapshot it. // consider the checkpoint trusted and snapshot it.
if number == 0 || (number%p.config.Epoch == 0 && (len(headers) > params.FullImmutabilityThreshold)) { if number == 0 || (number%p.config.Epoch == 0 && (len(headers) > params.FullImmutabilityThreshold/10)) {
checkpoint := chain.GetHeaderByNumber(number) checkpoint := chain.GetHeaderByNumber(number)
if checkpoint != nil { if checkpoint != nil {
// get checkpoint data // get checkpoint data
@ -694,10 +694,12 @@ func (p *Parlia) snapshot(chain consensus.ChainHeaderReader, number uint64, hash
// new snapshot // new snapshot
snap = newSnapshot(p.config, p.signatures, number, hash, validators, voteAddrs, p.ethAPI) snap = newSnapshot(p.config, p.signatures, number, hash, validators, voteAddrs, p.ethAPI)
if err := snap.store(p.db); err != nil { if snap.Number%checkpointInterval == 0 { // snapshot will only be loaded when snap.Number%checkpointInterval == 0
return nil, err if err := snap.store(p.db); err != nil {
return nil, err
}
log.Info("Stored checkpoint snapshot to disk", "number", number, "hash", hash)
} }
log.Info("Stored checkpoint snapshot to disk", "number", number, "hash", hash)
break break
} }
} }
@ -828,6 +830,13 @@ func (p *Parlia) prepareValidators(header *types.Header) error {
} }
} else { } else {
header.Extra = append(header.Extra, byte(len(newValidators))) header.Extra = append(header.Extra, byte(len(newValidators)))
if p.chainConfig.IsOnLuban(header.Number) {
voteAddressMap = make(map[common.Address]*types.BLSPublicKey, len(newValidators))
var zeroBlsKey types.BLSPublicKey
for _, validator := range newValidators {
voteAddressMap[validator] = &zeroBlsKey
}
}
for _, validator := range newValidators { for _, validator := range newValidators {
header.Extra = append(header.Extra, validator.Bytes()...) header.Extra = append(header.Extra, validator.Bytes()...)
header.Extra = append(header.Extra, voteAddressMap[validator].Bytes()...) header.Extra = append(header.Extra, voteAddressMap[validator].Bytes()...)
@ -989,6 +998,13 @@ func (p *Parlia) verifyValidators(header *types.Header) error {
return errMismatchingEpochValidators return errMismatchingEpochValidators
} }
validatorsBytes = make([]byte, validatorsNumber*validatorBytesLength) validatorsBytes = make([]byte, validatorsNumber*validatorBytesLength)
if p.chainConfig.IsOnLuban(header.Number) {
voteAddressMap = make(map[common.Address]*types.BLSPublicKey, len(newValidators))
var zeroBlsKey types.BLSPublicKey
for _, validator := range newValidators {
voteAddressMap[validator] = &zeroBlsKey
}
}
for i, validator := range newValidators { for i, validator := range newValidators {
copy(validatorsBytes[i*validatorBytesLength:], validator.Bytes()) copy(validatorsBytes[i*validatorBytesLength:], validator.Bytes())
copy(validatorsBytes[i*validatorBytesLength+common.AddressLength:], voteAddressMap[validator].Bytes()) copy(validatorsBytes[i*validatorBytesLength+common.AddressLength:], voteAddressMap[validator].Bytes())
@ -1556,7 +1572,8 @@ func (p *Parlia) distributeIncoming(val common.Address, state *state.StateDB, he
state.SetBalance(consensus.SystemAddress, big.NewInt(0)) state.SetBalance(consensus.SystemAddress, big.NewInt(0))
state.AddBalance(coinbase, balance) state.AddBalance(coinbase, balance)
doDistributeSysReward := state.GetBalance(common.HexToAddress(systemcontracts.SystemRewardContract)).Cmp(maxSystemBalance) < 0 doDistributeSysReward := !p.chainConfig.IsKepler(header.Number, header.Time) &&
state.GetBalance(common.HexToAddress(systemcontracts.SystemRewardContract)).Cmp(maxSystemBalance) < 0
if doDistributeSysReward { if doDistributeSysReward {
var rewards = new(big.Int) var rewards = new(big.Int)
rewards = rewards.Rsh(balance, systemRewardPercent) rewards = rewards.Rsh(balance, systemRewardPercent)

@ -199,6 +199,9 @@ func (s *Snapshot) updateAttestation(header *types.Header, chainConfig *params.C
} }
// Update attestation // Update attestation
// Two scenarios for s.Attestation being nil:
// 1) The first attestation is assembled.
// 2) The snapshot on disk is missing, prompting the creation of a new snapshot using `newSnapshot`.
if s.Attestation != nil && attestation.Data.SourceNumber+1 != attestation.Data.TargetNumber { if s.Attestation != nil && attestation.Data.SourceNumber+1 != attestation.Data.TargetNumber {
s.Attestation.TargetNumber = attestation.Data.TargetNumber s.Attestation.TargetNumber = attestation.Data.TargetNumber
s.Attestation.TargetHash = attestation.Data.TargetHash s.Attestation.TargetHash = attestation.Data.TargetHash

@ -552,7 +552,7 @@ func (bc *BlockChain) GetVMConfig() *vm.Config {
return &bc.vmConfig return &bc.vmConfig
} }
func (bc *BlockChain) cacheReceipts(hash common.Hash, receipts types.Receipts) { func (bc *BlockChain) cacheReceipts(hash common.Hash, receipts types.Receipts, block *types.Block) {
// TODO, This is a hot fix for the block hash of logs is `0x0000000000000000000000000000000000000000000000000000000000000000` for system tx // TODO, This is a hot fix for the block hash of logs is `0x0000000000000000000000000000000000000000000000000000000000000000` for system tx
// Please check details in https://github.com/bnb-chain/bsc/issues/443 // Please check details in https://github.com/bnb-chain/bsc/issues/443
// This is a temporary fix, the official fix should be a hard fork. // This is a temporary fix, the official fix should be a hard fork.
@ -563,6 +563,16 @@ func (bc *BlockChain) cacheReceipts(hash common.Hash, receipts types.Receipts) {
receipts[i].Logs[j].BlockHash = hash receipts[i].Logs[j].BlockHash = hash
} }
} }
txs := block.Transactions()
if len(txs) != len(receipts) {
log.Warn("transaction and receipt count mismatch")
return
}
for i, receipt := range receipts {
receipt.EffectiveGasPrice = txs[i].EffectiveGasTipValue(block.BaseFee()) // basefee is supposed to be nil or zero
}
bc.receiptsCache.Add(hash, receipts) bc.receiptsCache.Add(hash, receipts)
} }
@ -2049,7 +2059,6 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
vtime := time.Since(vstart) vtime := time.Since(vstart)
proctime := time.Since(start) // processing + validation proctime := time.Since(start) // processing + validation
bc.cacheReceipts(block.Hash(), receipts)
bc.cacheBlock(block.Hash(), block) bc.cacheBlock(block.Hash(), block)
// Update the metrics touched during block processing and validation // Update the metrics touched during block processing and validation
@ -2082,6 +2091,9 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
if err != nil { if err != nil {
return it.index, err return it.index, err
} }
bc.cacheReceipts(block.Hash(), receipts, block)
// Update the metrics touched during block commit // Update the metrics touched during block commit
accountCommitTimer.Update(statedb.AccountCommits) // Account commits are complete, we can mark them accountCommitTimer.Update(statedb.AccountCommits) // Account commits are complete, we can mark them
storageCommitTimer.Update(statedb.StorageCommits) // Storage commits are complete, we can mark them storageCommitTimer.Update(statedb.StorageCommits) // Storage commits are complete, we can mark them

@ -308,7 +308,7 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse
if config.DAOForkSupport && config.DAOForkBlock != nil && config.DAOForkBlock.Cmp(b.header.Number) == 0 { if config.DAOForkSupport && config.DAOForkBlock != nil && config.DAOForkBlock.Cmp(b.header.Number) == 0 {
misc.ApplyDAOHardFork(statedb) misc.ApplyDAOHardFork(statedb)
} }
systemcontracts.UpgradeBuildInSystemContract(config, b.header.Number, statedb) systemcontracts.UpgradeBuildInSystemContract(config, b.header.Number, parent.Time(), b.header.Time, statedb)
// Execute any user modifications to the block // Execute any user modifications to the block
if gen != nil { if gen != nil {
gen(i, b) gen(i, b)

@ -534,7 +534,7 @@ func (g *Genesis) ToBlock() *types.Block {
var withdrawals []*types.Withdrawal var withdrawals []*types.Withdrawal
if conf := g.Config; conf != nil { if conf := g.Config; conf != nil {
num := big.NewInt(int64(g.Number)) num := big.NewInt(int64(g.Number))
if conf.IsShanghai(num, g.Timestamp) { if conf.Parlia == nil && conf.IsShanghai(num, g.Timestamp) {
head.WithdrawalsHash = &types.EmptyWithdrawalsHash head.WithdrawalsHash = &types.EmptyWithdrawalsHash
withdrawals = make([]*types.Withdrawal, 0) withdrawals = make([]*types.Withdrawal, 0)
} }

@ -74,7 +74,11 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
misc.ApplyDAOHardFork(statedb) misc.ApplyDAOHardFork(statedb)
} }
// Handle upgrade build-in system contract code // Handle upgrade build-in system contract code
systemcontracts.UpgradeBuildInSystemContract(p.config, block.Number(), statedb) lastBlock := p.bc.GetBlockByHash(block.ParentHash())
if lastBlock == nil {
return statedb, nil, nil, 0, fmt.Errorf("could not get parent block")
}
systemcontracts.UpgradeBuildInSystemContract(p.config, blockNumber, lastBlock.Time(), block.Time(), statedb)
var ( var (
context = NewEVMBlockContext(header, p.bc, nil) context = NewEVMBlockContext(header, p.bc, nil)

File diff suppressed because one or more lines are too long

@ -90,7 +90,7 @@ func newCancunInstructionSet() JumpTable {
} }
func newShanghaiInstructionSet() JumpTable { func newShanghaiInstructionSet() JumpTable {
instructionSet := newMergeInstructionSet() instructionSet := newLondonInstructionSet()
enable3855(&instructionSet) // PUSH0 instruction enable3855(&instructionSet) // PUSH0 instruction
enable3860(&instructionSet) // Limit and meter initcode enable3860(&instructionSet) // Limit and meter initcode

@ -118,42 +118,40 @@ func TestFilters(t *testing.T) {
contract = common.Address{0xfe} contract = common.Address{0xfe}
contract2 = common.Address{0xff} contract2 = common.Address{0xff}
abiStr = `[{"inputs":[],"name":"log0","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"t1","type":"uint256"}],"name":"log1","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"t1","type":"uint256"},{"internalType":"uint256","name":"t2","type":"uint256"}],"name":"log2","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"t1","type":"uint256"},{"internalType":"uint256","name":"t2","type":"uint256"},{"internalType":"uint256","name":"t3","type":"uint256"}],"name":"log3","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"t1","type":"uint256"},{"internalType":"uint256","name":"t2","type":"uint256"},{"internalType":"uint256","name":"t3","type":"uint256"},{"internalType":"uint256","name":"t4","type":"uint256"}],"name":"log4","outputs":[],"stateMutability":"nonpayable","type":"function"}]` abiStr = `[{"inputs":[],"name":"log0","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"t1","type":"uint256"}],"name":"log1","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"t1","type":"uint256"},{"internalType":"uint256","name":"t2","type":"uint256"}],"name":"log2","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"t1","type":"uint256"},{"internalType":"uint256","name":"t2","type":"uint256"},{"internalType":"uint256","name":"t3","type":"uint256"}],"name":"log3","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"t1","type":"uint256"},{"internalType":"uint256","name":"t2","type":"uint256"},{"internalType":"uint256","name":"t3","type":"uint256"},{"internalType":"uint256","name":"t4","type":"uint256"}],"name":"log4","outputs":[],"stateMutability":"nonpayable","type":"function"}]`
// BaseFee in BSC is 0 now, use 1Gwei instead for test here to avoid 0 gasPrice
gasPrice1Gwei = big.NewInt(params.GWei)
/* /*
// SPDX-License-Identifier: GPL-3.0 // SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0; pragma solidity >=0.7.0 <0.9.0;
contract Logger { contract Logger {
function log0() external { function log0() external {
assembly { assembly {
log0(0, 0) log0(0, 0)
} }
} }
function log1(uint t1) external { function log1(uint t1) external {
assembly { assembly {
log1(0, 0, t1) log1(0, 0, t1)
} }
} }
function log2(uint t1, uint t2) external { function log2(uint t1, uint t2) external {
assembly { assembly {
log2(0, 0, t1, t2) log2(0, 0, t1, t2)
} }
} }
function log3(uint t1, uint t2, uint t3) external { function log3(uint t1, uint t2, uint t3) external {
assembly { assembly {
log3(0, 0, t1, t2, t3) log3(0, 0, t1, t2, t3)
} }
} }
function log4(uint t1, uint t2, uint t3, uint t4) external { function log4(uint t1, uint t2, uint t3, uint t4) external {
assembly { assembly {
log4(0, 0, t1, t2, t3, t4) log4(0, 0, t1, t2, t3, t4)
} }
} }
} }
*/ */
bytecode = common.FromHex("608060405234801561001057600080fd5b50600436106100575760003560e01c80630aa731851461005c5780632a4c08961461006657806378b9a1f314610082578063c670f8641461009e578063c683d6a3146100ba575b600080fd5b6100646100d6565b005b610080600480360381019061007b9190610143565b6100dc565b005b61009c60048036038101906100979190610196565b6100e8565b005b6100b860048036038101906100b391906101d6565b6100f2565b005b6100d460048036038101906100cf9190610203565b6100fa565b005b600080a0565b808284600080a3505050565b8082600080a25050565b80600080a150565b80828486600080a450505050565b600080fd5b6000819050919050565b6101208161010d565b811461012b57600080fd5b50565b60008135905061013d81610117565b92915050565b60008060006060848603121561015c5761015b610108565b5b600061016a8682870161012e565b935050602061017b8682870161012e565b925050604061018c8682870161012e565b9150509250925092565b600080604083850312156101ad576101ac610108565b5b60006101bb8582860161012e565b92505060206101cc8582860161012e565b9150509250929050565b6000602082840312156101ec576101eb610108565b5b60006101fa8482850161012e565b91505092915050565b6000806000806080858703121561021d5761021c610108565b5b600061022b8782880161012e565b945050602061023c8782880161012e565b935050604061024d8782880161012e565b925050606061025e8782880161012e565b9150509295919450925056fea264697066735822122073a4b156f487e59970dc1ef449cc0d51467268f676033a17188edafcee861f9864736f6c63430008110033") bytecode = common.FromHex("608060405234801561001057600080fd5b50600436106100575760003560e01c80630aa731851461005c5780632a4c08961461006657806378b9a1f314610082578063c670f8641461009e578063c683d6a3146100ba575b600080fd5b6100646100d6565b005b610080600480360381019061007b9190610143565b6100dc565b005b61009c60048036038101906100979190610196565b6100e8565b005b6100b860048036038101906100b391906101d6565b6100f2565b005b6100d460048036038101906100cf9190610203565b6100fa565b005b600080a0565b808284600080a3505050565b8082600080a25050565b80600080a150565b80828486600080a450505050565b600080fd5b6000819050919050565b6101208161010d565b811461012b57600080fd5b50565b60008135905061013d81610117565b92915050565b60008060006060848603121561015c5761015b610108565b5b600061016a8682870161012e565b935050602061017b8682870161012e565b925050604061018c8682870161012e565b9150509250925092565b600080604083850312156101ad576101ac610108565b5b60006101bb8582860161012e565b92505060206101cc8582860161012e565b9150509250929050565b6000602082840312156101ec576101eb610108565b5b60006101fa8482850161012e565b91505092915050565b6000806000806080858703121561021d5761021c610108565b5b600061022b8782880161012e565b945050602061023c8782880161012e565b935050604061024d8782880161012e565b925050606061025e8782880161012e565b9150509295919450925056fea264697066735822122073a4b156f487e59970dc1ef449cc0d51467268f676033a17188edafcee861f9864736f6c63430008110033")
@ -171,9 +169,7 @@ func TestFilters(t *testing.T) {
contract: {Balance: big.NewInt(0), Code: bytecode}, contract: {Balance: big.NewInt(0), Code: bytecode},
contract2: {Balance: big.NewInt(0), Code: bytecode}, contract2: {Balance: big.NewInt(0), Code: bytecode},
}, },
// Ethereum's InitialBaseFee is 1000000000, while BSC is 0, here is to fix CI BaseFee: big.NewInt(params.InitialBaseFeeForEthMainnet),
// BaseFee: big.NewInt(params.InitialBaseFee),
BaseFee: gasPrice1Gwei,
} }
) )
@ -197,7 +193,7 @@ func TestFilters(t *testing.T) {
} }
tx, _ := types.SignTx(types.NewTx(&types.LegacyTx{ tx, _ := types.SignTx(types.NewTx(&types.LegacyTx{
Nonce: 0, Nonce: 0,
GasPrice: gasPrice1Gwei, GasPrice: gen.BaseFee(),
Gas: 30000, Gas: 30000,
To: &contract, To: &contract,
Data: data, Data: data,
@ -205,7 +201,7 @@ func TestFilters(t *testing.T) {
gen.AddTx(tx) gen.AddTx(tx)
tx2, _ := types.SignTx(types.NewTx(&types.LegacyTx{ tx2, _ := types.SignTx(types.NewTx(&types.LegacyTx{
Nonce: 1, Nonce: 1,
GasPrice: gasPrice1Gwei, GasPrice: gen.BaseFee(),
Gas: 30000, Gas: 30000,
To: &contract2, To: &contract2,
Data: data, Data: data,
@ -218,7 +214,7 @@ func TestFilters(t *testing.T) {
} }
tx, _ := types.SignTx(types.NewTx(&types.LegacyTx{ tx, _ := types.SignTx(types.NewTx(&types.LegacyTx{
Nonce: 2, Nonce: 2,
GasPrice: gasPrice1Gwei, GasPrice: gen.BaseFee(),
Gas: 30000, Gas: 30000,
To: &contract, To: &contract,
Data: data, Data: data,
@ -231,7 +227,7 @@ func TestFilters(t *testing.T) {
} }
tx, _ := types.SignTx(types.NewTx(&types.LegacyTx{ tx, _ := types.SignTx(types.NewTx(&types.LegacyTx{
Nonce: 3, Nonce: 3,
GasPrice: gasPrice1Gwei, GasPrice: gen.BaseFee(),
Gas: 30000, Gas: 30000,
To: &contract2, To: &contract2,
Data: data, Data: data,
@ -244,7 +240,7 @@ func TestFilters(t *testing.T) {
} }
tx, _ := types.SignTx(types.NewTx(&types.LegacyTx{ tx, _ := types.SignTx(types.NewTx(&types.LegacyTx{
Nonce: 4, Nonce: 4,
GasPrice: gasPrice1Gwei, GasPrice: gen.BaseFee(),
Gas: 30000, Gas: 30000,
To: &contract, To: &contract,
Data: data, Data: data,
@ -290,61 +286,74 @@ func TestFilters(t *testing.T) {
}{ }{
{ {
f: sys.NewBlockFilter(chain[2].Hash(), []common.Address{contract}, nil), f: sys.NewBlockFilter(chain[2].Hash(), []common.Address{contract}, nil),
want: `[{"address":"0xfe00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696332","0x0000000000000000000000000000000000000000000000000000746f70696331"],"data":"0x","blockNumber":"0x3","transactionHash":"0x0dc0e230687c0b67421b862b6ac7af9d21c157fd5f41d35266bf148f21c754b4","transactionIndex":"0x0","blockHash":"0x552c4d4884746b710049d85c8d6e3c420ff021ff65244672fcdcd82154c9292b","logIndex":"0x0","removed":false}]`, want: `[{"address":"0xfe00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696332","0x0000000000000000000000000000000000000000000000000000746f70696331"],"data":"0x","blockNumber":"0x3","transactionHash":"0xdefe471992a07a02acdfbe33edaae22fbb86d7d3cec3f1b8e4e77702fb3acc1d","transactionIndex":"0x0","blockHash":"0x7a7556792ca7d37882882e2b001fe14833eaf81c2c7f865c9c771ec37a024f6b","logIndex":"0x0","removed":false}]`,
}, { },
{
f: sys.NewRangeFilter(0, int64(rpc.LatestBlockNumber), []common.Address{contract}, [][]common.Hash{{hash1, hash2, hash3, hash4}}, false), f: sys.NewRangeFilter(0, int64(rpc.LatestBlockNumber), []common.Address{contract}, [][]common.Hash{{hash1, hash2, hash3, hash4}}, false),
want: `[{"address":"0xfe00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696331"],"data":"0x","blockNumber":"0x2","transactionHash":"0x251cd3065f17245a0a6d528d74ae8bd6f008813e19319d14154bfda99b2e742d","transactionIndex":"0x0","blockHash":"0x41f1a563f54d6ce4330db1ad87c51b8ac3b68b9379e35b51e8c5e9b030b1f1b1","logIndex":"0x0","removed":false},{"address":"0xfe00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696332","0x0000000000000000000000000000000000000000000000000000746f70696331"],"data":"0x","blockNumber":"0x3","transactionHash":"0x0dc0e230687c0b67421b862b6ac7af9d21c157fd5f41d35266bf148f21c754b4","transactionIndex":"0x0","blockHash":"0x552c4d4884746b710049d85c8d6e3c420ff021ff65244672fcdcd82154c9292b","logIndex":"0x0","removed":false},{"address":"0xfe00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696334"],"data":"0x","blockNumber":"0x3e8","transactionHash":"0x71bbc18e2797e26e27fef2e9dd6a65e1eff6421735e9568ea805fc4a57f20482","transactionIndex":"0x0","blockHash":"0x7f0be2e908e7a6b2bcbab9dc574a9050338ed6c6db592bd97be21d4f1a69518a","logIndex":"0x0","removed":false}]`, want: `[{"address":"0xfe00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696331"],"data":"0x","blockNumber":"0x2","transactionHash":"0xa8028c655b6423204c8edfbc339f57b042d6bec2b6a61145d76b7c08b4cccd42","transactionIndex":"0x0","blockHash":"0x24417bb49ce44cfad65da68f33b510bf2a129c0d89ccf06acb6958b8585ccf34","logIndex":"0x0","removed":false},{"address":"0xfe00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696332","0x0000000000000000000000000000000000000000000000000000746f70696331"],"data":"0x","blockNumber":"0x3","transactionHash":"0xdefe471992a07a02acdfbe33edaae22fbb86d7d3cec3f1b8e4e77702fb3acc1d","transactionIndex":"0x0","blockHash":"0x7a7556792ca7d37882882e2b001fe14833eaf81c2c7f865c9c771ec37a024f6b","logIndex":"0x0","removed":false},{"address":"0xfe00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696334"],"data":"0x","blockNumber":"0x3e8","transactionHash":"0x9a87842100a638dfa5da8842b4beda691d2fd77b0c84b57f24ecfa9fb208f747","transactionIndex":"0x0","blockHash":"0xb360bad5265261c075ece02d3bf0e39498a6a76310482cdfd90588748e6c5ee0","logIndex":"0x0","removed":false}]`,
}, { },
{
f: sys.NewRangeFilter(900, 999, []common.Address{contract}, [][]common.Hash{{hash3}}, false), f: sys.NewRangeFilter(900, 999, []common.Address{contract}, [][]common.Hash{{hash3}}, false),
}, { },
{
f: sys.NewRangeFilter(990, int64(rpc.LatestBlockNumber), []common.Address{contract2}, [][]common.Hash{{hash3}}, false), f: sys.NewRangeFilter(990, int64(rpc.LatestBlockNumber), []common.Address{contract2}, [][]common.Hash{{hash3}}, false),
want: `[{"address":"0xff00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696333"],"data":"0x","blockNumber":"0x3e7","transactionHash":"0xcaea5cabe64d59ac0c74ca2eed41b1ef36dc996415ca085396d0f5acb0094935","transactionIndex":"0x0","blockHash":"0xf926a72aac711b12c385bdb7e935c49c3b77b4a857e4c924d9bfcf940694f3c1","logIndex":"0x0","removed":false}]`, want: `[{"address":"0xff00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696333"],"data":"0x","blockNumber":"0x3e7","transactionHash":"0x53e3675800c6908424b61b35a44e51ca4c73ca603e58a65b32c67968b4f42200","transactionIndex":"0x0","blockHash":"0x2e4620a2b426b0612ec6cad9603f466723edaed87f98c9137405dd4f7a2409ff","logIndex":"0x0","removed":false}]`,
}, { },
{
f: sys.NewRangeFilter(1, 10, []common.Address{contract}, [][]common.Hash{{hash2}, {hash1}}, false), f: sys.NewRangeFilter(1, 10, []common.Address{contract}, [][]common.Hash{{hash2}, {hash1}}, false),
want: `[{"address":"0xfe00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696332","0x0000000000000000000000000000000000000000000000000000746f70696331"],"data":"0x","blockNumber":"0x3","transactionHash":"0x0dc0e230687c0b67421b862b6ac7af9d21c157fd5f41d35266bf148f21c754b4","transactionIndex":"0x0","blockHash":"0x552c4d4884746b710049d85c8d6e3c420ff021ff65244672fcdcd82154c9292b","logIndex":"0x0","removed":false}]`, want: `[{"address":"0xfe00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696332","0x0000000000000000000000000000000000000000000000000000746f70696331"],"data":"0x","blockNumber":"0x3","transactionHash":"0xdefe471992a07a02acdfbe33edaae22fbb86d7d3cec3f1b8e4e77702fb3acc1d","transactionIndex":"0x0","blockHash":"0x7a7556792ca7d37882882e2b001fe14833eaf81c2c7f865c9c771ec37a024f6b","logIndex":"0x0","removed":false}]`,
}, { },
{
f: sys.NewRangeFilter(1, 10, nil, [][]common.Hash{{hash1, hash2}}, false), f: sys.NewRangeFilter(1, 10, nil, [][]common.Hash{{hash1, hash2}}, false),
want: `[{"address":"0xfe00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696331"],"data":"0x","blockNumber":"0x2","transactionHash":"0x251cd3065f17245a0a6d528d74ae8bd6f008813e19319d14154bfda99b2e742d","transactionIndex":"0x0","blockHash":"0x41f1a563f54d6ce4330db1ad87c51b8ac3b68b9379e35b51e8c5e9b030b1f1b1","logIndex":"0x0","removed":false},{"address":"0xff00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696331"],"data":"0x","blockNumber":"0x2","transactionHash":"0x7afd31c9d543a1056ca2d35ce106408f1cb925546fc3a97f337122ca5a9e515e","transactionIndex":"0x1","blockHash":"0x41f1a563f54d6ce4330db1ad87c51b8ac3b68b9379e35b51e8c5e9b030b1f1b1","logIndex":"0x1","removed":false},{"address":"0xfe00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696332","0x0000000000000000000000000000000000000000000000000000746f70696331"],"data":"0x","blockNumber":"0x3","transactionHash":"0x0dc0e230687c0b67421b862b6ac7af9d21c157fd5f41d35266bf148f21c754b4","transactionIndex":"0x0","blockHash":"0x552c4d4884746b710049d85c8d6e3c420ff021ff65244672fcdcd82154c9292b","logIndex":"0x0","removed":false}]`, want: `[{"address":"0xfe00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696331"],"data":"0x","blockNumber":"0x2","transactionHash":"0xa8028c655b6423204c8edfbc339f57b042d6bec2b6a61145d76b7c08b4cccd42","transactionIndex":"0x0","blockHash":"0x24417bb49ce44cfad65da68f33b510bf2a129c0d89ccf06acb6958b8585ccf34","logIndex":"0x0","removed":false},{"address":"0xff00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696331"],"data":"0x","blockNumber":"0x2","transactionHash":"0xdba3e2ea9a7d690b722d70ee605fd67ba4c00d1d3aecd5cf187a7b92ad8eb3df","transactionIndex":"0x1","blockHash":"0x24417bb49ce44cfad65da68f33b510bf2a129c0d89ccf06acb6958b8585ccf34","logIndex":"0x1","removed":false},{"address":"0xfe00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696332","0x0000000000000000000000000000000000000000000000000000746f70696331"],"data":"0x","blockNumber":"0x3","transactionHash":"0xdefe471992a07a02acdfbe33edaae22fbb86d7d3cec3f1b8e4e77702fb3acc1d","transactionIndex":"0x0","blockHash":"0x7a7556792ca7d37882882e2b001fe14833eaf81c2c7f865c9c771ec37a024f6b","logIndex":"0x0","removed":false}]`,
}, { },
{
f: sys.NewRangeFilter(0, int64(rpc.LatestBlockNumber), nil, [][]common.Hash{{common.BytesToHash([]byte("fail"))}}, false), f: sys.NewRangeFilter(0, int64(rpc.LatestBlockNumber), nil, [][]common.Hash{{common.BytesToHash([]byte("fail"))}}, false),
}, { },
{
f: sys.NewRangeFilter(0, int64(rpc.LatestBlockNumber), []common.Address{common.BytesToAddress([]byte("failmenow"))}, nil, false), f: sys.NewRangeFilter(0, int64(rpc.LatestBlockNumber), []common.Address{common.BytesToAddress([]byte("failmenow"))}, nil, false),
}, { },
{
f: sys.NewRangeFilter(0, int64(rpc.LatestBlockNumber), nil, [][]common.Hash{{common.BytesToHash([]byte("fail"))}, {hash1}}, false), f: sys.NewRangeFilter(0, int64(rpc.LatestBlockNumber), nil, [][]common.Hash{{common.BytesToHash([]byte("fail"))}, {hash1}}, false),
}, { },
{
f: sys.NewRangeFilter(int64(rpc.LatestBlockNumber), int64(rpc.LatestBlockNumber), nil, nil, false), f: sys.NewRangeFilter(int64(rpc.LatestBlockNumber), int64(rpc.LatestBlockNumber), nil, nil, false),
want: `[{"address":"0xfe00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696334"],"data":"0x","blockNumber":"0x3e8","transactionHash":"0x71bbc18e2797e26e27fef2e9dd6a65e1eff6421735e9568ea805fc4a57f20482","transactionIndex":"0x0","blockHash":"0x7f0be2e908e7a6b2bcbab9dc574a9050338ed6c6db592bd97be21d4f1a69518a","logIndex":"0x0","removed":false}]`, want: `[{"address":"0xfe00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696334"],"data":"0x","blockNumber":"0x3e8","transactionHash":"0x9a87842100a638dfa5da8842b4beda691d2fd77b0c84b57f24ecfa9fb208f747","transactionIndex":"0x0","blockHash":"0xb360bad5265261c075ece02d3bf0e39498a6a76310482cdfd90588748e6c5ee0","logIndex":"0x0","removed":false}]`,
}, },
/* /*
// BSC's finalize logic is different from Ethereum, it is achieved from snapshot, no SetFinalized
// So skip finality related cases
{ {
f: sys.NewRangeFilter(int64(rpc.FinalizedBlockNumber), int64(rpc.LatestBlockNumber), nil, nil, false), f: sys.NewRangeFilter(int64(rpc.FinalizedBlockNumber), int64(rpc.LatestBlockNumber), nil, nil, false),
want: `[{"address":"0xff00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696333"],"data":"0x","blockNumber":"0x3e7","transactionHash":"0xcaea5cabe64d59ac0c74ca2eed41b1ef36dc996415ca085396d0f5acb0094935","transactionIndex":"0x0","blockHash":"0xf926a72aac711b12c385bdb7e935c49c3b77b4a857e4c924d9bfcf940694f3c1","logIndex":"0x0","removed":false},{"address":"0xfe00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696334"],"data":"0x","blockNumber":"0x3e8","transactionHash":"0x71bbc18e2797e26e27fef2e9dd6a65e1eff6421735e9568ea805fc4a57f20482","transactionIndex":"0x0","blockHash":"0x7f0be2e908e7a6b2bcbab9dc574a9050338ed6c6db592bd97be21d4f1a69518a","logIndex":"0x0","removed":false}]`, want: `[{"address":"0xff00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696333"],"data":"0x","blockNumber":"0x3e7","transactionHash":"0x53e3675800c6908424b61b35a44e51ca4c73ca603e58a65b32c67968b4f42200","transactionIndex":"0x0","blockHash":"0x2e4620a2b426b0612ec6cad9603f466723edaed87f98c9137405dd4f7a2409ff","logIndex":"0x0","removed":false},{"address":"0xfe00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696334"],"data":"0x","blockNumber":"0x3e8","transactionHash":"0x9a87842100a638dfa5da8842b4beda691d2fd77b0c84b57f24ecfa9fb208f747","transactionIndex":"0x0","blockHash":"0xb360bad5265261c075ece02d3bf0e39498a6a76310482cdfd90588748e6c5ee0","logIndex":"0x0","removed":false}]`,
}, },
{ {
f: sys.NewRangeFilter(int64(rpc.FinalizedBlockNumber), int64(rpc.FinalizedBlockNumber), nil, nil, false), f: sys.NewRangeFilter(int64(rpc.FinalizedBlockNumber), int64(rpc.FinalizedBlockNumber), nil, nil, false),
want: `[{"address":"0xff00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696333"],"data":"0x","blockNumber":"0x3e7","transactionHash":"0xcaea5cabe64d59ac0c74ca2eed41b1ef36dc996415ca085396d0f5acb0094935","transactionIndex":"0x0","blockHash":"0xf926a72aac711b12c385bdb7e935c49c3b77b4a857e4c924d9bfcf940694f3c1","logIndex":"0x0","removed":false}]`, want: `[{"address":"0xff00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696333"],"data":"0x","blockNumber":"0x3e7","transactionHash":"0x53e3675800c6908424b61b35a44e51ca4c73ca603e58a65b32c67968b4f42200","transactionIndex":"0x0","blockHash":"0x2e4620a2b426b0612ec6cad9603f466723edaed87f98c9137405dd4f7a2409ff","logIndex":"0x0","removed":false}]`,
}, { },
f: sys.NewRangeFilter(int64(rpc.LatestBlockNumber), int64(rpc.FinalizedBlockNumber), nil, nil, false), {
}, { f: sys.NewRangeFilter(int64(rpc.LatestBlockNumber), int64(rpc.FinalizedBlockNumber), nil, nil),
f: sys.NewRangeFilter(int64(rpc.SafeBlockNumber), int64(rpc.LatestBlockNumber), nil, nil, false), },
{
f: sys.NewRangeFilter(int64(rpc.SafeBlockNumber), int64(rpc.LatestBlockNumber), nil, nil),
err: "safe header not found", err: "safe header not found",
}, { },
f: sys.NewRangeFilter(int64(rpc.SafeBlockNumber), int64(rpc.SafeBlockNumber), nil, nil, false), {
f: sys.NewRangeFilter(int64(rpc.SafeBlockNumber), int64(rpc.SafeBlockNumber), nil, nil),
err: "safe header not found", err: "safe header not found",
}, { },
f: sys.NewRangeFilter(int64(rpc.LatestBlockNumber), int64(rpc.SafeBlockNumber), nil, nil, false), {
f: sys.NewRangeFilter(int64(rpc.LatestBlockNumber), int64(rpc.SafeBlockNumber), nil, nil),
err: "safe header not found", err: "safe header not found",
}, },
*/ */
{ {
f: sys.NewRangeFilter(int64(rpc.PendingBlockNumber), int64(rpc.PendingBlockNumber), nil, nil, false), f: sys.NewRangeFilter(int64(rpc.PendingBlockNumber), int64(rpc.PendingBlockNumber), nil, nil, false),
want: `[{"address":"0xfe00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696335"],"data":"0x","blockNumber":"0x3e9","transactionHash":"0xb2bb61fcb8a26dae28e833ba97e2e87cfb8d3dcdfe77f9375b8a5a2e62a890e9","transactionIndex":"0x0","blockHash":"0x53a4ca36e4e3108ce28f140f80327c4851a5eb5717abd8324d3bb6fc07fdc328","logIndex":"0x0","removed":false}]`, want: `[{"address":"0xfe00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696335"],"data":"0x","blockNumber":"0x3e9","transactionHash":"0x4110587c1b8d86edc85dce929a34127f1cb8809515a9f177c91c866de3eb0638","transactionIndex":"0x0","blockHash":"0xc7245899e5817f16fa99cf5ad2d9c1e4b98443a565a673ec9c764640443ef037","logIndex":"0x0","removed":false}]`,
}, { },
{
f: sys.NewRangeFilter(int64(rpc.LatestBlockNumber), int64(rpc.PendingBlockNumber), nil, nil, false), f: sys.NewRangeFilter(int64(rpc.LatestBlockNumber), int64(rpc.PendingBlockNumber), nil, nil, false),
want: `[{"address":"0xfe00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696334"],"data":"0x","blockNumber":"0x3e8","transactionHash":"0x71bbc18e2797e26e27fef2e9dd6a65e1eff6421735e9568ea805fc4a57f20482","transactionIndex":"0x0","blockHash":"0x7f0be2e908e7a6b2bcbab9dc574a9050338ed6c6db592bd97be21d4f1a69518a","logIndex":"0x0","removed":false},{"address":"0xfe00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696335"],"data":"0x","blockNumber":"0x3e9","transactionHash":"0xb2bb61fcb8a26dae28e833ba97e2e87cfb8d3dcdfe77f9375b8a5a2e62a890e9","transactionIndex":"0x0","blockHash":"0x53a4ca36e4e3108ce28f140f80327c4851a5eb5717abd8324d3bb6fc07fdc328","logIndex":"0x0","removed":false}]`, want: `[{"address":"0xfe00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696334"],"data":"0x","blockNumber":"0x3e8","transactionHash":"0x9a87842100a638dfa5da8842b4beda691d2fd77b0c84b57f24ecfa9fb208f747","transactionIndex":"0x0","blockHash":"0xb360bad5265261c075ece02d3bf0e39498a6a76310482cdfd90588748e6c5ee0","logIndex":"0x0","removed":false},{"address":"0xfe00000000000000000000000000000000000000","topics":["0x0000000000000000000000000000000000000000000000000000746f70696335"],"data":"0x","blockNumber":"0x3e9","transactionHash":"0x4110587c1b8d86edc85dce929a34127f1cb8809515a9f177c91c866de3eb0638","transactionIndex":"0x0","blockHash":"0xc7245899e5817f16fa99cf5ad2d9c1e4b98443a565a673ec9c764640443ef037","logIndex":"0x0","removed":false}]`,
}, { },
{
f: sys.NewRangeFilter(int64(rpc.PendingBlockNumber), int64(rpc.LatestBlockNumber), nil, nil, false), f: sys.NewRangeFilter(int64(rpc.PendingBlockNumber), int64(rpc.LatestBlockNumber), nil, nil, false),
err: "invalid block range", err: "invalid block range",
}, },

@ -27,6 +27,7 @@ import (
"sync/atomic" "sync/atomic"
"time" "time"
"github.com/cockroachdb/errors"
"github.com/cockroachdb/pebble" "github.com/cockroachdb/pebble"
"github.com/cockroachdb/pebble/bloom" "github.com/cockroachdb/pebble/bloom"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
@ -116,6 +117,16 @@ func (d *Database) onWriteStallEnd() {
d.writeDelayTime.Add(int64(time.Since(d.writeDelayStartTime))) d.writeDelayTime.Add(int64(time.Since(d.writeDelayStartTime)))
} }
// panicLogger is just a noop logger to disable Pebble's internal logger.
type panicLogger struct{}
func (l panicLogger) Infof(format string, args ...interface{}) {
}
func (l panicLogger) Fatalf(format string, args ...interface{}) {
panic(errors.Errorf("fatal: "+format, args...))
}
// New returns a wrapped pebble DB object. The namespace is the prefix that the // New returns a wrapped pebble DB object. The namespace is the prefix that the
// metrics reporting should use for surfacing internal stats. // metrics reporting should use for surfacing internal stats.
func New(file string, cache int, handles int, namespace string, readonly bool) (*Database, error) { func New(file string, cache int, handles int, namespace string, readonly bool) (*Database, error) {
@ -127,7 +138,6 @@ func New(file string, cache int, handles int, namespace string, readonly bool) (
handles = minHandles handles = minHandles
} }
logger := log.New("database", file) logger := log.New("database", file)
logger.Info("Allocated cache and file handles", "cache", common.StorageSize(cache*1024*1024), "handles", handles)
// The max memtable size is limited by the uint32 offsets stored in // The max memtable size is limited by the uint32 offsets stored in
// internal/arenaskl.node, DeferredBatchOp, and flushableBatchEntry. // internal/arenaskl.node, DeferredBatchOp, and flushableBatchEntry.
@ -141,6 +151,10 @@ func New(file string, cache int, handles int, namespace string, readonly bool) (
if memTableSize > maxMemTableSize { if memTableSize > maxMemTableSize {
memTableSize = maxMemTableSize memTableSize = maxMemTableSize
} }
logger.Info("Allocated cache and file handles", "cache", common.StorageSize(cache*1024*1024),
"handles", handles, "memory table", common.StorageSize(memTableSize))
db := &Database{ db := &Database{
fn: file, fn: file,
log: logger, log: logger,
@ -155,7 +169,7 @@ func New(file string, cache int, handles int, namespace string, readonly bool) (
// The size of memory table(as well as the write buffer). // The size of memory table(as well as the write buffer).
// Note, there may have more than two memory tables in the system. // Note, there may have more than two memory tables in the system.
MemTableSize: memTableSize, MemTableSize: uint64(memTableSize),
// MemTableStopWritesThreshold places a hard limit on the size // MemTableStopWritesThreshold places a hard limit on the size
// of the existent MemTables(including the frozen one). // of the existent MemTables(including the frozen one).
@ -170,15 +184,6 @@ func New(file string, cache int, handles int, namespace string, readonly bool) (
// Per-level options. Options for at least one level must be specified. The // Per-level options. Options for at least one level must be specified. The
// options for the last level are used for all subsequent levels. // options for the last level are used for all subsequent levels.
Levels: []pebble.LevelOptions{
{TargetFileSize: 2 * 1024 * 1024, FilterPolicy: bloom.FilterPolicy(10)},
{TargetFileSize: 2 * 1024 * 1024, FilterPolicy: bloom.FilterPolicy(10)},
{TargetFileSize: 2 * 1024 * 1024, FilterPolicy: bloom.FilterPolicy(10)},
{TargetFileSize: 2 * 1024 * 1024, FilterPolicy: bloom.FilterPolicy(10)},
{TargetFileSize: 2 * 1024 * 1024, FilterPolicy: bloom.FilterPolicy(10)},
{TargetFileSize: 2 * 1024 * 1024, FilterPolicy: bloom.FilterPolicy(10)},
{TargetFileSize: 2 * 1024 * 1024, FilterPolicy: bloom.FilterPolicy(10)},
},
ReadOnly: readonly, ReadOnly: readonly,
EventListener: &pebble.EventListener{ EventListener: &pebble.EventListener{
CompactionBegin: db.onCompactionBegin, CompactionBegin: db.onCompactionBegin,
@ -186,7 +191,21 @@ func New(file string, cache int, handles int, namespace string, readonly bool) (
WriteStallBegin: db.onWriteStallBegin, WriteStallBegin: db.onWriteStallBegin,
WriteStallEnd: db.onWriteStallEnd, WriteStallEnd: db.onWriteStallEnd,
}, },
Logger: panicLogger{}, // TODO(karalabe): Delete when this is upstreamed in Pebble
} }
for i := 0; i < len(opt.Levels); i++ {
l := &opt.Levels[i]
l.BlockSize = 32 << 10 // 32 KB
l.IndexBlockSize = 256 << 10 // 256 KB
l.FilterPolicy = bloom.FilterPolicy(10)
l.FilterType = pebble.TableFilter
if i > 0 {
l.TargetFileSize = opt.Levels[i-1].TargetFileSize * 2
}
l.EnsureDefaults()
}
// Disable seek compaction explicitly. Check https://github.com/ethereum/go-ethereum/pull/20130 // Disable seek compaction explicitly. Check https://github.com/ethereum/go-ethereum/pull/20130
// for more details. // for more details.
opt.Experimental.ReadSamplingMultiplier = -1 opt.Experimental.ReadSamplingMultiplier = -1
@ -305,9 +324,9 @@ func (d *Database) NewBatch() ethdb.Batch {
// It's not supported by pebble, but pebble has better memory allocation strategy // It's not supported by pebble, but pebble has better memory allocation strategy
// which turns out a lot faster than leveldb. It's performant enough to construct // which turns out a lot faster than leveldb. It's performant enough to construct
// batch object without any pre-allocated space. // batch object without any pre-allocated space.
func (d *Database) NewBatchWithSize(_ int) ethdb.Batch { func (d *Database) NewBatchWithSize(size int) ethdb.Batch {
return &batch{ return &batch{
b: d.db.NewBatch(), b: d.db.NewBatchWithSize(size),
db: d, db: d,
} }
} }
@ -576,7 +595,7 @@ type pebbleIterator struct {
// of database content with a particular key prefix, starting at a particular // of database content with a particular key prefix, starting at a particular
// initial key (or after, if it does not exist). // initial key (or after, if it does not exist).
func (d *Database) NewIterator(prefix []byte, start []byte) ethdb.Iterator { func (d *Database) NewIterator(prefix []byte, start []byte) ethdb.Iterator {
iter := d.db.NewIter(&pebble.IterOptions{ iter, _ := d.db.NewIter(&pebble.IterOptions{
LowerBound: append(prefix, start...), LowerBound: append(prefix, start...),
UpperBound: upperBound(prefix), UpperBound: upperBound(prefix),
}) })

5
go.mod

@ -13,7 +13,8 @@ require (
github.com/btcsuite/btcd/btcec/v2 v2.3.2 github.com/btcsuite/btcd/btcec/v2 v2.3.2
github.com/cespare/cp v1.1.1 github.com/cespare/cp v1.1.1
github.com/cloudflare/cloudflare-go v0.14.0 github.com/cloudflare/cloudflare-go v0.14.0
github.com/cockroachdb/pebble v0.0.0-20230906160148-46873a6a7a06 github.com/cockroachdb/errors v1.9.1
github.com/cockroachdb/pebble v0.0.0-20230928194634-aa077af62593
github.com/cometbft/cometbft v0.37.0 github.com/cometbft/cometbft v0.37.0
github.com/consensys/gnark-crypto v0.10.0 github.com/consensys/gnark-crypto v0.10.0
github.com/crate-crypto/go-kzg-4844 v0.3.0 github.com/crate-crypto/go-kzg-4844 v0.3.0
@ -109,9 +110,9 @@ require (
github.com/cespare/xxhash v1.1.0 // indirect github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chzyer/readline v1.5.1 // indirect github.com/chzyer/readline v1.5.1 // indirect
github.com/cockroachdb/errors v1.9.1 // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/redact v1.1.3 // indirect github.com/cockroachdb/redact v1.1.3 // indirect
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/consensys/bavard v0.1.13 // indirect github.com/consensys/bavard v0.1.13 // indirect
github.com/containerd/cgroups v1.1.0 // indirect github.com/containerd/cgroups v1.1.0 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect github.com/coreos/go-systemd/v22 v22.5.0 // indirect

8
go.sum

@ -247,16 +247,18 @@ github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnht
github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8= github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
github.com/cockroachdb/datadriven v1.0.2/go.mod h1:a9RdTaap04u637JoCzcUoIcDmvwSUtcUFtT/C3kJlTU= github.com/cockroachdb/datadriven v1.0.2/go.mod h1:a9RdTaap04u637JoCzcUoIcDmvwSUtcUFtT/C3kJlTU=
github.com/cockroachdb/datadriven v1.0.3-0.20230801171734-e384cf455877 h1:1MLK4YpFtIEo3ZtMA5C795Wtv5VuUnrXX7mQG+aHg6o= github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f h1:otljaYPt5hWxV3MUfO5dFPFiOXg9CyG5/kCfayTqsJ4=
github.com/cockroachdb/errors v1.9.1 h1:yFVvsI0VxmRShfawbt/laCIDy/mtTqqnvoNgiy5bEV8= github.com/cockroachdb/errors v1.9.1 h1:yFVvsI0VxmRShfawbt/laCIDy/mtTqqnvoNgiy5bEV8=
github.com/cockroachdb/errors v1.9.1/go.mod h1:2sxOtL2WIc096WSZqZ5h8fa17rdDq9HZOZLBCor4mBk= github.com/cockroachdb/errors v1.9.1/go.mod h1:2sxOtL2WIc096WSZqZ5h8fa17rdDq9HZOZLBCor4mBk=
github.com/cockroachdb/logtags v0.0.0-20211118104740-dabe8e521a4f/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs= github.com/cockroachdb/logtags v0.0.0-20211118104740-dabe8e521a4f/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs=
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE= github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE=
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs= github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs=
github.com/cockroachdb/pebble v0.0.0-20230906160148-46873a6a7a06 h1:T+Np/xtzIjYM/P5NAw0e2Rf1FGvzDau1h54MKvx8G7w= github.com/cockroachdb/pebble v0.0.0-20230928194634-aa077af62593 h1:aPEJyR4rPBvDmeyi+l/FS/VtA00IWvjeFvjen1m1l1A=
github.com/cockroachdb/pebble v0.0.0-20230906160148-46873a6a7a06/go.mod h1:bynZ3gvVyhlvjLI7PT6dmZ7g76xzJ7HpxfjgkzCGz6s= github.com/cockroachdb/pebble v0.0.0-20230928194634-aa077af62593/go.mod h1:6hk1eMY/u5t+Cf18q5lFMUA1Rc+Sm5I6Ra1QuPyxXCo=
github.com/cockroachdb/redact v1.1.3 h1:AKZds10rFSIj7qADf0g46UixK8NNLwWTNdCIGS5wfSQ= github.com/cockroachdb/redact v1.1.3 h1:AKZds10rFSIj7qADf0g46UixK8NNLwWTNdCIGS5wfSQ=
github.com/cockroachdb/redact v1.1.3/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= github.com/cockroachdb/redact v1.1.3/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 h1:zuQyyAKVxetITBuuhv3BI9cMrmStnpT18zmgmTxunpo=
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06/go.mod h1:7nc4anLGjupUW/PeY5qiNYsdNXj7zopG+eqsS7To5IQ=
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM= github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM=
github.com/cometbft/cometbft-db v0.7.0 h1:uBjbrBx4QzU0zOEnU8KxoDl18dMNgDh+zZRUE0ucsbo= github.com/cometbft/cometbft-db v0.7.0 h1:uBjbrBx4QzU0zOEnU8KxoDl18dMNgDh+zZRUE0ucsbo=

@ -914,7 +914,7 @@ func (w *worker) prepareWork(genParams *generateParams) (*environment, error) {
} }
// Handle upgrade build-in system contract code // Handle upgrade build-in system contract code
systemcontracts.UpgradeBuildInSystemContract(w.chainConfig, header.Number, env.state) systemcontracts.UpgradeBuildInSystemContract(w.chainConfig, header.Number, parent.Time, header.Time, env.state)
return env, nil return env, nil
} }

@ -159,15 +159,11 @@ var (
MoranBlock: big.NewInt(22107423), MoranBlock: big.NewInt(22107423),
GibbsBlock: big.NewInt(23846001), GibbsBlock: big.NewInt(23846001),
PlanckBlock: big.NewInt(27281024), PlanckBlock: big.NewInt(27281024),
LubanBlock: big.NewInt(29020050),
// TODO modify blockNumber, make sure the blockNumber is not an integer multiple of 200 (epoch number) PlatoBlock: big.NewInt(30720096),
// TODO Caution !!! it should be very careful !!! BerlinBlock: big.NewInt(31302048),
LubanBlock: big.NewInt(29020050), LondonBlock: big.NewInt(31302048),
PlatoBlock: big.NewInt(30720096), HertzBlock: big.NewInt(31302048),
// TODO modify blockNumber, make sure HertzBlock=BerlinBlock=LondonBlock to enable Berlin and London EIPs
BerlinBlock: big.NewInt(31302048),
LondonBlock: big.NewInt(31302048),
HertzBlock: big.NewInt(31302048),
Parlia: &ParliaConfig{ Parlia: &ParliaConfig{
Period: 3, Period: 3,
@ -195,15 +191,11 @@ var (
NanoBlock: big.NewInt(23482428), NanoBlock: big.NewInt(23482428),
MoranBlock: big.NewInt(23603940), MoranBlock: big.NewInt(23603940),
PlanckBlock: big.NewInt(28196022), PlanckBlock: big.NewInt(28196022),
LubanBlock: big.NewInt(29295050),
// TODO modify blockNumber, make sure the blockNumber is not an integer multiple of 200 (epoch number) PlatoBlock: big.NewInt(29861024),
// TODO Caution !!! it should be very careful !!! BerlinBlock: big.NewInt(31103030),
LubanBlock: big.NewInt(29295050), LondonBlock: big.NewInt(31103030),
PlatoBlock: big.NewInt(29861024), HertzBlock: big.NewInt(31103030),
// TODO modify blockNumber, make sure HertzBlock=BerlinBlock=LondonBlock to enable Berlin and London EIPs
BerlinBlock: big.NewInt(31103030),
LondonBlock: big.NewInt(31103030),
HertzBlock: big.NewInt(31103030),
Parlia: &ParliaConfig{ Parlia: &ParliaConfig{
Period: 3, Period: 3,
@ -231,12 +223,10 @@ var (
NanoBlock: nil, NanoBlock: nil,
MoranBlock: nil, MoranBlock: nil,
PlanckBlock: nil, PlanckBlock: nil,
LubanBlock: nil,
// TODO PlatoBlock: nil,
LubanBlock: nil, BerlinBlock: nil,
PlatoBlock: nil, HertzBlock: nil,
BerlinBlock: nil,
HertzBlock: nil,
Parlia: &ParliaConfig{ Parlia: &ParliaConfig{
Period: 3, Period: 3,
@ -458,6 +448,7 @@ type ChainConfig struct {
// Fork scheduling was switched from blocks to timestamps here // Fork scheduling was switched from blocks to timestamps here
ShanghaiTime *uint64 `json:"shanghaiTime,omitempty" toml:",omitempty"` // Shanghai switch time (nil = no fork, 0 = already on shanghai) ShanghaiTime *uint64 `json:"shanghaiTime,omitempty" toml:",omitempty"` // Shanghai switch time (nil = no fork, 0 = already on shanghai)
KeplerTime *uint64 `json:"keplerTime,omitempty" toml:",omitempty"` // Kepler switch time (nil = no fork, 0 = already activated)
CancunTime *uint64 `json:"cancunTime,omitempty" toml:",omitempty"` // Cancun switch time (nil = no fork, 0 = already on cancun) CancunTime *uint64 `json:"cancunTime,omitempty" toml:",omitempty"` // Cancun switch time (nil = no fork, 0 = already on cancun)
PragueTime *uint64 `json:"pragueTime,omitempty" toml:",omitempty"` // Prague switch time (nil = no fork, 0 = already on prague) PragueTime *uint64 `json:"pragueTime,omitempty" toml:",omitempty"` // Prague switch time (nil = no fork, 0 = already on prague)
VerkleTime *uint64 `json:"verkleTime,omitempty" toml:",omitempty"` // Verkle switch time (nil = no fork, 0 = already on verkle) VerkleTime *uint64 `json:"verkleTime,omitempty" toml:",omitempty"` // Verkle switch time (nil = no fork, 0 = already on verkle)
@ -540,7 +531,17 @@ func (c *ChainConfig) String() string {
engine = "unknown" engine = "unknown"
} }
return fmt.Sprintf("{ChainID: %v Homestead: %v DAO: %v DAOSupport: %v EIP150: %v EIP155: %v EIP158: %v Byzantium: %v Constantinople: %v Petersburg: %v Istanbul: %v, Muir Glacier: %v, Ramanujan: %v, Niels: %v, MirrorSync: %v, Bruno: %v, Berlin: %v, YOLO v3: %v, CatalystBlock: %v, London: %v, ArrowGlacier: %v, MergeFork:%v, Euler: %v, Gibbs: %v, Nano: %v, Moran: %v, Planck: %v,Luban: %v, Plato: %v, Hertz: %v, Engine: %v}", var ShanghaiTime *big.Int
if c.ShanghaiTime != nil {
ShanghaiTime = big.NewInt(0).SetUint64(*c.ShanghaiTime)
}
var KeplerTime *big.Int
if c.KeplerTime != nil {
KeplerTime = big.NewInt(0).SetUint64(*c.KeplerTime)
}
return fmt.Sprintf("{ChainID: %v Homestead: %v DAO: %v DAOSupport: %v EIP150: %v EIP155: %v EIP158: %v Byzantium: %v Constantinople: %v Petersburg: %v Istanbul: %v, Muir Glacier: %v, Ramanujan: %v, Niels: %v, MirrorSync: %v, Bruno: %v, Berlin: %v, YOLO v3: %v, CatalystBlock: %v, London: %v, ArrowGlacier: %v, MergeFork:%v, Euler: %v, Gibbs: %v, Nano: %v, Moran: %v, Planck: %v,Luban: %v, Plato: %v, Hertz: %v, ShanghaiTime: %v, KeplerTime: %v, Engine: %v}",
c.ChainID, c.ChainID,
c.HomesteadBlock, c.HomesteadBlock,
c.DAOForkBlock, c.DAOForkBlock,
@ -571,6 +572,8 @@ func (c *ChainConfig) String() string {
c.LubanBlock, c.LubanBlock,
c.PlatoBlock, c.PlatoBlock,
c.HertzBlock, c.HertzBlock,
ShanghaiTime,
KeplerTime,
engine, engine,
) )
} }
@ -774,6 +777,20 @@ func (c *ChainConfig) IsShanghai(num *big.Int, time uint64) bool {
return c.IsLondon(num) && isTimestampForked(c.ShanghaiTime, time) return c.IsLondon(num) && isTimestampForked(c.ShanghaiTime, time)
} }
// IsKepler returns whether time is either equal to the kepler fork time or greater.
func (c *ChainConfig) IsKepler(num *big.Int, time uint64) bool {
return c.IsLondon(num) && isTimestampForked(c.KeplerTime, time)
}
// IsOnKepler returns whether currentBlockTime is either equal to the kepler fork time or greater firstly.
func (c *ChainConfig) IsOnKepler(currentBlockNumber *big.Int, lastBlockTime uint64, currentBlockTime uint64) bool {
lastBlockNumber := new(big.Int)
if currentBlockNumber.Cmp(big.NewInt(1)) >= 0 {
lastBlockNumber.Sub(currentBlockNumber, big.NewInt(1))
}
return !c.IsKepler(lastBlockNumber, lastBlockTime) && c.IsKepler(currentBlockNumber, currentBlockTime)
}
// IsCancun returns whether num is either equal to the Cancun fork time or greater. // IsCancun returns whether num is either equal to the Cancun fork time or greater.
func (c *ChainConfig) IsCancun(num *big.Int, time uint64) bool { func (c *ChainConfig) IsCancun(num *big.Int, time uint64) bool {
return c.IsLondon(num) && isTimestampForked(c.CancunTime, time) return c.IsLondon(num) && isTimestampForked(c.CancunTime, time)
@ -971,6 +988,9 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, headNumber *big.Int,
if isForkTimestampIncompatible(c.ShanghaiTime, newcfg.ShanghaiTime, headTimestamp) { if isForkTimestampIncompatible(c.ShanghaiTime, newcfg.ShanghaiTime, headTimestamp) {
return newTimestampCompatError("Shanghai fork timestamp", c.ShanghaiTime, newcfg.ShanghaiTime) return newTimestampCompatError("Shanghai fork timestamp", c.ShanghaiTime, newcfg.ShanghaiTime)
} }
if isForkTimestampIncompatible(c.KeplerTime, newcfg.KeplerTime, headTimestamp) {
return newTimestampCompatError("Kepler fork timestamp", c.KeplerTime, newcfg.KeplerTime)
}
if isForkTimestampIncompatible(c.CancunTime, newcfg.CancunTime, headTimestamp) { if isForkTimestampIncompatible(c.CancunTime, newcfg.CancunTime, headTimestamp) {
return newTimestampCompatError("Cancun fork timestamp", c.CancunTime, newcfg.CancunTime) return newTimestampCompatError("Cancun fork timestamp", c.CancunTime, newcfg.CancunTime)
} }
@ -1131,7 +1151,7 @@ type Rules struct {
IsLuban bool IsLuban bool
IsPlato bool IsPlato bool
IsHertz bool IsHertz bool
IsShanghai, IsCancun, IsPrague bool IsShanghai, IsKepler, IsCancun, IsPrague bool
IsVerkle bool IsVerkle bool
} }
@ -1161,6 +1181,7 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp uint64) Rules
IsPlato: c.IsPlato(num), IsPlato: c.IsPlato(num),
IsHertz: c.IsHertz(num), IsHertz: c.IsHertz(num),
IsShanghai: c.IsShanghai(num, timestamp), IsShanghai: c.IsShanghai(num, timestamp),
IsKepler: c.IsKepler(num, timestamp),
IsCancun: c.IsCancun(num, timestamp), IsCancun: c.IsCancun(num, timestamp),
IsPrague: c.IsPrague(num, timestamp), IsPrague: c.IsPrague(num, timestamp),
IsVerkle: c.IsVerkle(num, timestamp), IsVerkle: c.IsVerkle(num, timestamp),

@ -30,7 +30,7 @@ func TestBlockchain(t *testing.T) {
// For speedier CI-runs, the line below can be uncommented, so those are skipped. // For speedier CI-runs, the line below can be uncommented, so those are skipped.
// For now, in hardfork-times (Berlin), we run the tests both as StateTests and // For now, in hardfork-times (Berlin), we run the tests both as StateTests and
// as blockchain tests, since the latter also covers things like receipt root // as blockchain tests, since the latter also covers things like receipt root
bt.skipLoad(`^GeneralStateTests/`) // bt.skipLoad(`^GeneralStateTests/`)
// Skip random failures due to selfish mining test // Skip random failures due to selfish mining test
bt.skipLoad(`.*bcForgedTest/bcForkUncle\.json`) bt.skipLoad(`.*bcForgedTest/bcForkUncle\.json`)
@ -49,6 +49,9 @@ func TestBlockchain(t *testing.T) {
// using 4.6 TGas // using 4.6 TGas
bt.skipLoad(`.*randomStatetest94.json.*`) bt.skipLoad(`.*randomStatetest94.json.*`)
bt.runonly(`^GeneralStateTests/Shanghai`)
bt.runonly(`^Pyspecs/shanghai/eip3.*`)
bt.walk(t, blockTestDir, func(t *testing.T, name string, test *BlockTest) { bt.walk(t, blockTestDir, func(t *testing.T, name string, test *BlockTest) {
if err := bt.checkFailure(t, test.Run(false, rawdb.HashScheme, nil)); err != nil { if err := bt.checkFailure(t, test.Run(false, rawdb.HashScheme, nil)); err != nil {
t.Errorf("test in hash mode without snapshotter failed: %v", err) t.Errorf("test in hash mode without snapshotter failed: %v", err)

@ -93,7 +93,7 @@ type testMatcher struct {
failpat []testFailure failpat []testFailure
skiploadpat []*regexp.Regexp skiploadpat []*regexp.Regexp
slowpat []*regexp.Regexp slowpat []*regexp.Regexp
runonlylistpat *regexp.Regexp runonlylistpat []*regexp.Regexp
} }
type testConfig struct { type testConfig struct {
@ -127,7 +127,7 @@ func (tm *testMatcher) fails(pattern string, reason string) {
} }
func (tm *testMatcher) runonly(pattern string) { func (tm *testMatcher) runonly(pattern string) {
tm.runonlylistpat = regexp.MustCompile(pattern) tm.runonlylistpat = append(tm.runonlylistpat, regexp.MustCompile(pattern))
} }
// config defines chain config for tests matching the pattern. // config defines chain config for tests matching the pattern.
@ -220,7 +220,14 @@ func (tm *testMatcher) runTestFile(t *testing.T, path, name string, runTest inte
t.Skip(r) t.Skip(r)
} }
if tm.runonlylistpat != nil { if tm.runonlylistpat != nil {
if !tm.runonlylistpat.MatchString(name) { match := false
for _, pat := range tm.runonlylistpat {
if pat.MatchString(name) {
match = true
break
}
}
if !match {
t.Skip("Skipped by runonly") t.Skip("Skipped by runonly")
} }
} }

@ -68,6 +68,8 @@ func TestState(t *testing.T) {
st.fails(`stEIP4844-blobtransactions/opcodeBlobhashOutOfRange.json`, "test has incorrect state root") st.fails(`stEIP4844-blobtransactions/opcodeBlobhashOutOfRange.json`, "test has incorrect state root")
st.fails(`stEIP4844-blobtransactions/opcodeBlobhBounds.json`, "test has incorrect state root") st.fails(`stEIP4844-blobtransactions/opcodeBlobhBounds.json`, "test has incorrect state root")
st.runonly(`^Shanghai`)
// For Istanbul, older tests were moved into LegacyTests // For Istanbul, older tests were moved into LegacyTests
for _, dir := range []string{ for _, dir := range []string{
filepath.Join(baseDir, "EIPTests", "StateTests"), filepath.Join(baseDir, "EIPTests", "StateTests"),

@ -300,7 +300,7 @@ func (t *StateTest) RunNoVerify(subtest StateSubtest, vmconfig vm.Config, snapsh
// And _now_ get the state root // And _now_ get the state root
root := statedb.IntermediateRoot(config.IsEIP158(block.Number())) root := statedb.IntermediateRoot(config.IsEIP158(block.Number()))
statedb.SetExpectedStateRoot(root) statedb.SetExpectedStateRoot(root)
root, _, err = statedb.Commit(block.NumberU64(), nil) root, _, _ = statedb.Commit(block.NumberU64(), nil)
return triedb, snaps, statedb, root, err return triedb, snaps, statedb, root, err
} }

@ -172,7 +172,7 @@ func New(diskdb ethdb.Database, config *Config) *Database {
// mechanism also ensures that at most one **non-readOnly** database // mechanism also ensures that at most one **non-readOnly** database
// is opened at the same time to prevent accidental mutation. // is opened at the same time to prevent accidental mutation.
if ancient, err := diskdb.AncientDatadir(); err == nil && ancient != "" && !db.readOnly { if ancient, err := diskdb.AncientDatadir(); err == nil && ancient != "" && !db.readOnly {
offset := uint64(0) //TODO(Nathan): just for passing compilation offset := uint64(0) // differ from in block data, only metadata is used in state data
freezer, err := rawdb.NewStateFreezer(ancient, false, offset) freezer, err := rawdb.NewStateFreezer(ancient, false, offset)
if err != nil { if err != nil {
log.Crit("Failed to open state history freezer", "err", err) log.Crit("Failed to open state history freezer", "err", err)