mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
fix: testcases
This commit is contained in:
parent
cdf58273c9
commit
687cd76405
4 changed files with 48 additions and 51 deletions
|
|
@ -572,11 +572,27 @@ func NewParallelBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis
|
|||
return bc, nil
|
||||
}
|
||||
|
||||
func (bc *BlockChain) ProcessBlock(block *types.Block, parent *types.Header) (types.Receipts, []*types.Log, uint64, *state.StateDB, error) {
|
||||
func (bc *BlockChain) ProcessBlock(block *types.Block, parent *types.Header) (_ types.Receipts, _ []*types.Log, _ uint64, _ *state.StateDB, blockEndErr error) {
|
||||
// Process the block using processor and parallelProcessor at the same time, take the one which finishes first, cancel the other, and return the result
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
if bc.logger != nil && bc.logger.OnBlockStart != nil {
|
||||
td := bc.GetTd(block.ParentHash(), block.NumberU64()-1)
|
||||
bc.logger.OnBlockStart(tracing.BlockEvent{
|
||||
Block: block,
|
||||
TD: td,
|
||||
Finalized: bc.CurrentFinalBlock(),
|
||||
Safe: bc.CurrentSafeBlock(),
|
||||
})
|
||||
}
|
||||
|
||||
if bc.logger != nil && bc.logger.OnBlockEnd != nil {
|
||||
defer func() {
|
||||
bc.logger.OnBlockEnd(blockEndErr)
|
||||
}()
|
||||
}
|
||||
|
||||
type Result struct {
|
||||
receipts types.Receipts
|
||||
logs []*types.Log
|
||||
|
|
@ -595,6 +611,7 @@ func (bc *BlockChain) ProcessBlock(block *types.Block, parent *types.Header) (ty
|
|||
if err != nil {
|
||||
return nil, nil, 0, nil, err
|
||||
}
|
||||
parallelStatedb.SetLogger(bc.logger)
|
||||
|
||||
processorCount++
|
||||
|
||||
|
|
@ -618,6 +635,7 @@ func (bc *BlockChain) ProcessBlock(block *types.Block, parent *types.Header) (ty
|
|||
if err != nil {
|
||||
return nil, nil, 0, nil, err
|
||||
}
|
||||
statedb.SetLogger(bc.logger)
|
||||
|
||||
processorCount++
|
||||
|
||||
|
|
@ -631,6 +649,7 @@ func (bc *BlockChain) ProcessBlock(block *types.Block, parent *types.Header) (ty
|
|||
}
|
||||
}
|
||||
statedb.StartPrefetcher("chain", witness)
|
||||
|
||||
receipts, logs, usedGas, err := bc.processor.Process(block, statedb, bc.vmConfig, ctx)
|
||||
resultChan <- Result{receipts, logs, usedGas, err, statedb, blockExecutionSerialCounter}
|
||||
}()
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package legacypool
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
|
@ -129,11 +130,18 @@ func TestFilterTxConditional(t *testing.T) {
|
|||
|
||||
options.KnownAccounts = types.KnownAccounts{
|
||||
common.Address{19: 1}: &types.Value{
|
||||
Single: common.HexToRefHash("0xe734938daf39aae1fa4ee64dc3155d7c049f28b57a8ada8ad9e86832e0253bef"),
|
||||
Single: common.HexToRefHash("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"),
|
||||
},
|
||||
}
|
||||
|
||||
trie, _ := state.StorageTrie(common.Address{19: 1})
|
||||
fmt.Println("before", trie)
|
||||
|
||||
state.SetState(common.Address{19: 1}, common.Hash{}, common.Hash{30: 1})
|
||||
|
||||
trie, _ = state.StorageTrie(common.Address{19: 1})
|
||||
fmt.Println("after", trie.Hash())
|
||||
|
||||
tx2.PutOptions(&options)
|
||||
list.Add(tx2, DefaultConfig.PriceBump)
|
||||
|
||||
|
|
@ -146,6 +154,9 @@ func TestFilterTxConditional(t *testing.T) {
|
|||
// Set state that conflicts with tx2's policy
|
||||
state.SetState(common.Address{19: 1}, common.Hash{}, common.Hash{31: 1})
|
||||
|
||||
trie, _ = state.StorageTrie(common.Address{19: 1})
|
||||
fmt.Println("after2", trie.Hash())
|
||||
|
||||
// tx2 should be the single transaction filtered out
|
||||
drops = list.FilterTxConditional(state)
|
||||
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ func TestFeeHistory(t *testing.T) {
|
|||
MaxHeaderHistory: c.maxHeader,
|
||||
MaxBlockHistory: c.maxBlock,
|
||||
}
|
||||
backend := newTestBackend(t, big.NewInt(16), big.NewInt(28), c.pending)
|
||||
backend := newTestBackend(t, big.NewInt(16), nil, c.pending)
|
||||
oracle := NewOracle(backend, config)
|
||||
|
||||
first, reward, baseFee, ratio, blobBaseFee, blobRatio, err := oracle.FeeHistory(context.Background(), c.count, c.last, c.percent)
|
||||
|
|
|
|||
|
|
@ -18,26 +18,21 @@ package gasprice
|
|||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"math"
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/consensus"
|
||||
"github.com/ethereum/go-ethereum/consensus/beacon"
|
||||
"github.com/ethereum/go-ethereum/consensus/ethash"
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
"github.com/ethereum/go-ethereum/core/rawdb"
|
||||
"github.com/ethereum/go-ethereum/core/state"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/core/vm"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/crypto/kzg4844"
|
||||
"github.com/ethereum/go-ethereum/event"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/holiman/uint256"
|
||||
)
|
||||
|
||||
const testHead = 32
|
||||
|
|
@ -151,28 +146,25 @@ func newTestBackend(t *testing.T, londonBlock *big.Int, cancunBlock *big.Int, pe
|
|||
Alloc: types.GenesisAlloc{addr: {Balance: big.NewInt(math.MaxInt64)}},
|
||||
}
|
||||
signer = types.LatestSigner(gspec.Config)
|
||||
|
||||
// Compute empty blob hash.
|
||||
emptyBlob = kzg4844.Blob{}
|
||||
emptyBlobCommit, _ = kzg4844.BlobToCommitment(&emptyBlob)
|
||||
emptyBlobVHash = kzg4844.CalcBlobHashV1(sha256.New(), &emptyBlobCommit)
|
||||
)
|
||||
|
||||
config.LondonBlock = londonBlock
|
||||
config.ArrowGlacierBlock = londonBlock
|
||||
config.GrayGlacierBlock = londonBlock
|
||||
var engine consensus.Engine = beacon.New(ethash.NewFaker())
|
||||
td := params.GenesisDifficulty.Uint64()
|
||||
config.TerminalTotalDifficulty = common.Big0
|
||||
// var engine consensus.Engine = beacon.New(ethash.NewFaker())
|
||||
// td := params.GenesisDifficulty.Uint64()
|
||||
engine := ethash.NewFaker()
|
||||
|
||||
if cancunBlock != nil {
|
||||
// if cancunBlock != nil {
|
||||
// ts := gspec.Timestamp + cancunBlock.Uint64()*10 // fixed 10 sec block time in blockgen
|
||||
config.ShanghaiBlock = londonBlock
|
||||
config.CancunBlock = cancunBlock
|
||||
signer = types.LatestSigner(gspec.Config)
|
||||
}
|
||||
// config.ShanghaiTime = &ts
|
||||
// config.CancunTime = &ts
|
||||
// signer = types.LatestSigner(gspec.Config)
|
||||
// }
|
||||
|
||||
// Generate testing blocks
|
||||
db, blocks, _ := core.GenerateChainWithGenesis(gspec, engine, testHead+1, func(i int, b *core.BlockGen) {
|
||||
_, blocks, _ := core.GenerateChainWithGenesis(gspec, engine, testHead+1, func(i int, b *core.BlockGen) {
|
||||
b.SetCoinbase(common.Address{1})
|
||||
|
||||
var txdata types.TxData
|
||||
|
|
@ -198,39 +190,14 @@ func newTestBackend(t *testing.T, londonBlock *big.Int, cancunBlock *big.Int, pe
|
|||
}
|
||||
|
||||
b.AddTx(types.MustSignNewTx(key, signer, txdata))
|
||||
|
||||
if cancunBlock != nil && b.Number().Cmp(cancunBlock) >= 0 {
|
||||
b.SetPoS()
|
||||
|
||||
// put more blobs in each new block
|
||||
for j := 0; j < i && j < 6; j++ {
|
||||
blobTx := &types.BlobTx{
|
||||
ChainID: uint256.MustFromBig(gspec.Config.ChainID),
|
||||
Nonce: b.TxNonce(addr),
|
||||
To: common.Address{},
|
||||
Gas: 30000,
|
||||
GasFeeCap: uint256.NewInt(100 * params.GWei),
|
||||
GasTipCap: uint256.NewInt(uint64(i+1) * params.GWei),
|
||||
Data: []byte{},
|
||||
BlobFeeCap: uint256.NewInt(1),
|
||||
BlobHashes: []common.Hash{emptyBlobVHash},
|
||||
Value: uint256.NewInt(100),
|
||||
Sidecar: nil,
|
||||
}
|
||||
b.AddTx(types.MustSignNewTx(key, signer, blobTx))
|
||||
}
|
||||
}
|
||||
td += b.Difficulty().Uint64()
|
||||
})
|
||||
// Construct testing chain
|
||||
gspec.Config.TerminalTotalDifficulty = new(big.Int).SetUint64(td)
|
||||
chain, err := core.NewBlockChain(db, &core.CacheConfig{TrieCleanNoPrefetch: true}, gspec, nil, engine, vm.Config{}, nil, nil, nil)
|
||||
chain, err := core.NewBlockChain(rawdb.NewMemoryDatabase(), &core.CacheConfig{TrieCleanNoPrefetch: true}, gspec, nil, engine, vm.Config{}, nil, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create local chain, %v", err)
|
||||
}
|
||||
if i, err := chain.InsertChain(blocks); err != nil {
|
||||
panic(fmt.Errorf("error inserting block %d: %w", i, err))
|
||||
}
|
||||
|
||||
chain.InsertChain(blocks)
|
||||
chain.SetFinalized(chain.GetBlockByNumber(25).Header())
|
||||
chain.SetSafe(chain.GetBlockByNumber(25).Header())
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue