Skip to content

Commit

Permalink
Align with coreth (ava-labs#1067)
Browse files Browse the repository at this point in the history
  • Loading branch information
darioush authored Jan 30, 2024
1 parent a8c7424 commit 840876a
Show file tree
Hide file tree
Showing 39 changed files with 168 additions and 158 deletions.
7 changes: 3 additions & 4 deletions accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,8 @@ func NewSimulatedBackendWithDatabase(database ethdb.Database, alloc core.Genesis
Alloc: alloc,
}
cacheConfig := &core.CacheConfig{}
blockchain, err := core.NewBlockChain(database, cacheConfig, &genesis, dummy.NewCoinbaseFaker(), vm.Config{}, common.Hash{}, false)
if err != nil {
panic(fmt.Sprintf("failed to create simulated blockchain: %v", err))
}
blockchain, _ := core.NewBlockChain(database, cacheConfig, &genesis, dummy.NewCoinbaseFaker(), vm.Config{}, common.Hash{}, false)

backend := &SimulatedBackend{
database: database,
blockchain: blockchain,
Expand Down Expand Up @@ -610,6 +608,7 @@ func (b *SimulatedBackend) EstimateGas(ctx context.Context, call interfaces.Call
for lo+1 < hi {
mid := (hi + lo) / 2
failed, _, err := executable(mid)

// If the error is not nil(consensus error), it means the provided message
// call or transaction will never be accepted no matter how much gas it is
// assigned. Return the error directly, don't struggle any more
Expand Down
134 changes: 75 additions & 59 deletions accounts/abi/bind/bind_test.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion consensus/dummy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The dummy consensus engine is responsible for performing verification on the hea

Subnet-EVM includes a dynamic fee algorithm based off of (EIP-1559)[https://eips.ethereum.org/EIPS/eip-1559]. This introduces a field to the block type called `BaseFee`. The Base Fee sets a minimum gas price for any transaction to be included in the block. For example, a transaction with a gas price of 49 gwei, will be invalid to include in a block with a base fee of 50 gwei.

The dynamic fee algorithm aims to adjust the base fee to handle network congestion. Subnet-EVM sets a target utilization on the network, and the dynamic fee algorithm adjusts the base fee accordingly. If the network operates above the target utilization, the dynamic fee algorithm will increase the base fee to make utilizing he network more expensive and bring overall utilization down. If the network operates below the target utilization, the dynamic fee algorithm will decrease the base fee to make it cheaper to use the network.
The dynamic fee algorithm aims to adjust the base fee to handle network congestion. Subnet-EVM sets a target utilization on the network, and the dynamic fee algorithm adjusts the base fee accordingly. If the network operates above the target utilization, the dynamic fee algorithm will increase the base fee to make utilizing the network more expensive and bring overall utilization down. If the network operates below the target utilization, the dynamic fee algorithm will decrease the base fee to make it cheaper to use the network.

- EIP-1559 is intended for Ethereum where a block is produced roughly every 10s
- The dynamic fee algorithm needs to handle the case that the network quiesces and there are no blocks for a long period of time
Expand Down
22 changes: 1 addition & 21 deletions core/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"testing"

"github.com/ava-labs/subnet-evm/consensus/dummy"
"github.com/ava-labs/subnet-evm/constants"
"github.com/ava-labs/subnet-evm/core/rawdb"
"github.com/ava-labs/subnet-evm/core/types"
"github.com/ava-labs/subnet-evm/core/vm"
Expand All @@ -46,39 +45,31 @@ import (
func BenchmarkInsertChain_empty_memdb(b *testing.B) {
benchInsertChain(b, false, nil)
}

func BenchmarkInsertChain_empty_diskdb(b *testing.B) {
benchInsertChain(b, true, nil)
}

func BenchmarkInsertChain_valueTx_memdb(b *testing.B) {
benchInsertChain(b, false, genValueTx(0))
}

func BenchmarkInsertChain_valueTx_diskdb(b *testing.B) {
benchInsertChain(b, true, genValueTx(0))
}

func BenchmarkInsertChain_valueTx_100kB_memdb(b *testing.B) {
benchInsertChain(b, false, genValueTx(100*1024))
}

func BenchmarkInsertChain_valueTx_100kB_diskdb(b *testing.B) {
benchInsertChain(b, true, genValueTx(100*1024))
}

func BenchmarkInsertChain_ring200_memdb(b *testing.B) {
benchInsertChain(b, false, genTxRing(200))
}

func BenchmarkInsertChain_ring200_diskdb(b *testing.B) {
benchInsertChain(b, true, genTxRing(200))
}

func BenchmarkInsertChain_ring1000_memdb(b *testing.B) {
benchInsertChain(b, false, genTxRing(1000))
}

func BenchmarkInsertChain_ring1000_diskdb(b *testing.B) {
benchInsertChain(b, true, genTxRing(1000))
}
Expand Down Expand Up @@ -187,47 +178,36 @@ func benchInsertChain(b *testing.B, disk bool, gen func(int, *BlockGen)) {
func BenchmarkChainRead_header_10k(b *testing.B) {
benchReadChain(b, false, 10000)
}

func BenchmarkChainRead_full_10k(b *testing.B) {
benchReadChain(b, true, 10000)
}

func BenchmarkChainRead_header_100k(b *testing.B) {
benchReadChain(b, false, 100000)
}

func BenchmarkChainRead_full_100k(b *testing.B) {
benchReadChain(b, true, 100000)
}

func BenchmarkChainRead_header_500k(b *testing.B) {
benchReadChain(b, false, 500000)
}

func BenchmarkChainRead_full_500k(b *testing.B) {
benchReadChain(b, true, 500000)
}

func BenchmarkChainWrite_header_10k(b *testing.B) {
benchWriteChain(b, false, 10000)
}

func BenchmarkChainWrite_full_10k(b *testing.B) {
benchWriteChain(b, true, 10000)
}

func BenchmarkChainWrite_header_100k(b *testing.B) {
benchWriteChain(b, false, 100000)
}

func BenchmarkChainWrite_full_100k(b *testing.B) {
benchWriteChain(b, true, 100000)
}

func BenchmarkChainWrite_header_500k(b *testing.B) {
benchWriteChain(b, false, 500000)
}

func BenchmarkChainWrite_full_500k(b *testing.B) {
benchWriteChain(b, true, 500000)
}
Expand All @@ -238,7 +218,7 @@ func makeChainForBench(db ethdb.Database, full bool, count uint64) {
var hash common.Hash
for n := uint64(0); n < count; n++ {
header := &types.Header{
Coinbase: constants.BlackholeAddr,
Coinbase: common.Address{},
Number: big.NewInt(int64(n)),
ParentHash: hash,
Difficulty: big.NewInt(1),
Expand Down
4 changes: 1 addition & 3 deletions core/fifo_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@

package core

import (
"sync"
)
import "sync"

var (
_ FIFOCache[int, int] = (*BufferFIFOCache[int, int])(nil)
Expand Down
1 change: 0 additions & 1 deletion core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ func SetupGenesisBlock(
if genesis.Config == nil {
return nil, common.Hash{}, errGenesisNoConfig
}

// Just commit the new block if there is no stored genesis block.
stored := rawdb.ReadCanonicalHash(db, 0)
if (stored == common.Hash{}) {
Expand Down
2 changes: 1 addition & 1 deletion core/rawdb/chain_iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestChainIterator(t *testing.T) {
WriteCanonicalHash(chainDb, block.Hash(), block.NumberU64())
}

cases := []struct {
var cases = []struct {
from, to uint64
reverse bool
expect []int
Expand Down
2 changes: 1 addition & 1 deletion core/state/pruner/pruner.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ const warningLog = `
WARNING!
The clean trie cache is not found. Please delete it by yourself after the
The clean trie cache is not found. Please delete it by yourself after the
pruning. Remember don't start the Subnet-EVM without deleting the clean trie cache
otherwise the entire database may be damaged!
Expand Down
1 change: 1 addition & 0 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
if err := st.preCheck(); err != nil {
return nil, err
}

if tracer := st.evm.Config.Tracer; tracer != nil {
tracer.CaptureTxStart(st.initialGas)
defer func() {
Expand Down
6 changes: 3 additions & 3 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ func (evm *EVM) CallCode(caller ContractRef, addr common.Address, input []byte,
if !evm.Context.CanTransfer(evm.StateDB, caller.Address(), value) {
return nil, gas, vmerrs.ErrInsufficientBalance
}
snapshot := evm.StateDB.Snapshot()
var snapshot = evm.StateDB.Snapshot()

// Invoke tracer hooks that signal entering/exiting a call frame
if evm.Config.Tracer != nil {
Expand Down Expand Up @@ -394,7 +394,7 @@ func (evm *EVM) DelegateCall(caller ContractRef, addr common.Address, input []by
if evm.depth > int(params.CallCreateDepth) {
return nil, gas, vmerrs.ErrDepth
}
snapshot := evm.StateDB.Snapshot()
var snapshot = evm.StateDB.Snapshot()

// Invoke tracer hooks that signal entering/exiting a call frame
if evm.Config.Tracer != nil {
Expand Down Expand Up @@ -442,7 +442,7 @@ func (evm *EVM) StaticCall(caller ContractRef, addr common.Address, input []byte
// after all empty accounts were deleted, so this is not required. However, if we omit this,
// then certain tests start failing; stRevertTest/RevertPrecompiledTouchExactOOG.json.
// We could change this, but for now it's left for legacy reasons
snapshot := evm.StateDB.Snapshot()
var snapshot = evm.StateDB.Snapshot()

// We do an AddBalance of zero here, just in order to trigger a touch.
// This doesn't matter on Mainnet, where all empties are gone at the time of Byzantium,
Expand Down
1 change: 1 addition & 0 deletions core/vm/evm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func TestIsProhibited(t *testing.T) {

// allowed for use
assert.False(t, IsProhibited(common.HexToAddress("0x00000000000000000000000000000000000000ff")))
assert.False(t, IsProhibited(common.HexToAddress("0x00ffffffffffffffffffffffffffffffffffffff")))
assert.False(t, IsProhibited(common.HexToAddress("0x0100000000000000000000000000000000000100")))
assert.False(t, IsProhibited(common.HexToAddress("0x0200000000000000000000000000000000000100")))
assert.False(t, IsProhibited(common.HexToAddress("0x0300000000000000000000000000000000000100")))
Expand Down
4 changes: 2 additions & 2 deletions core/vm/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,8 +675,6 @@ func opCall(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byt
// Get the arguments from the memory.
args := scope.Memory.GetPtr(int64(inOffset.Uint64()), int64(inSize.Uint64()))

// Note: this code fails to check that value2 is zero, which was a bug when CALLEX was active.
// The CALLEX opcode was de-activated in ApricotPhase2 resolving this issue.
if interpreter.readOnly && !value.IsZero() {
return nil, vmerrs.ErrWriteProtection
}
Expand Down Expand Up @@ -855,6 +853,8 @@ func makeLog(size int) executionFunc {
scope.Contract.Address(),
topics,
d,
// This is a non-consensus field, but assigned here because
// core/state doesn't know the current block number.
interpreter.evm.Context.BlockNumber.Uint64(),
)

Expand Down
1 change: 0 additions & 1 deletion core/vm/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ type StateDB interface {

Suicide(common.Address) bool
HasSuicided(common.Address) bool
Finalise(deleteEmptyObjects bool)

// Exist reports whether the given account exists in state.
// Notably this should also return true for suicided accounts.
Expand Down
7 changes: 0 additions & 7 deletions core/vm/opcodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,6 @@ const (
TSTORE OpCode = 0xb4
)

// unofficial opcodes used for parsing.
const (
PUSH OpCode = 0xb0 + iota
DUP
SWAP
)

// 0xf0 range - closures.
const (
CREATE OpCode = 0xf0
Expand Down
4 changes: 1 addition & 3 deletions eth/gasprice/gasprice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,7 @@ func TestSuggestTipCapSmallTips(t *testing.T) {
Data: []byte{},
})
tx, err = types.SignTx(tx, signer, key)
if err != nil {
t.Fatalf("failed to create tx: %s", err)
}
require.NoError(t, err, "failed to create tx")
b.AddTx(tx)
}
},
Expand Down
1 change: 1 addition & 0 deletions eth/state_accessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ var noopReleaser = tracers.StateReleaseFunc(func() {})
// provided, it would be preferable to start from a fresh state, if we have it
// on disk.
func (eth *Ethereum) StateAtBlock(ctx context.Context, block *types.Block, reexec uint64, base *state.StateDB, readOnly bool, preferDisk bool) (statedb *state.StateDB, release tracers.StateReleaseFunc, err error) {
reexec = 0 // Do not support re-executing historical blocks to grab state
var (
current *types.Block
database state.Database
Expand Down
4 changes: 1 addition & 3 deletions eth/tracers/internal/tracetest/calltrace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/rlp"

// Force-load native, to trigger registration
_ "github.com/ava-labs/subnet-evm/eth/tracers/native"
)

type callContext struct {
Expand Down Expand Up @@ -297,6 +294,7 @@ func TestInternals(t *testing.T) {
}
return tr
}

for _, tc := range []struct {
name string
code []byte
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"byzantiumBlock": 0,
"constantinopleBlock": 0,
"petersburgBlock": 0,
"IstanbulBlock": 1561651,
"IstanbulBlock": 1561651,
"chainId": 5,
"eip150Block": 0,
"eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"byzantiumBlock": 0,
"constantinopleBlock": 0,
"petersburgBlock": 0,
"IstanbulBlock": 1561651,
"IstanbulBlock":1561651,
"chainId": 5,
"daoForkSupport": true,
"eip150Block": 0,
Expand Down
2 changes: 1 addition & 1 deletion miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (w *worker) commitNewWork(predicateContext *precompileconfig.PredicateConte
return nil, err
}

// Get the pending txs from TxPool
// Fill the block with all available pending transactions.
pending := w.eth.TxPool().Pending(true)

// Split the pending transactions into locals and remotes
Expand Down
8 changes: 4 additions & 4 deletions plugin/evm/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (b *Block) Accept(context.Context) error {
// precompiles are committed atomically with the vm's lastAcceptedKey.
rules := b.vm.chainConfig.AvalancheRules(b.ethBlock.Number(), b.ethBlock.Timestamp())
sharedMemoryWriter := NewSharedMemoryWriter()
if err := b.handlePrecompileAccept(&rules, sharedMemoryWriter); err != nil {
if err := b.handlePrecompileAccept(rules, sharedMemoryWriter); err != nil {
return err
}
if err := vm.blockChain.Accept(b.ethBlock); err != nil {
Expand All @@ -82,9 +82,9 @@ func (b *Block) Accept(context.Context) error {

// Get pending operations on the vm's versionDB so we can apply them atomically
// with the shared memory requests.
vdbBatch, err := vm.db.CommitBatch()
vdbBatch, err := b.vm.db.CommitBatch()
if err != nil {
return fmt.Errorf("failed to get commit batch: %w", err)
return fmt.Errorf("could not create commit batch processing block[%s]: %w", b.ID(), err)
}

// Apply any shared memory requests that accumulated from processing the logs
Expand All @@ -97,7 +97,7 @@ func (b *Block) Accept(context.Context) error {
// contract.Accepter
// This function assumes that the Accept function will ONLY operate on state maintained in the VM's versiondb.
// This ensures that any DB operations are performed atomically with marking the block as accepted.
func (b *Block) handlePrecompileAccept(rules *params.Rules, sharedMemoryWriter *sharedMemoryWriter) error {
func (b *Block) handlePrecompileAccept(rules params.Rules, sharedMemoryWriter *sharedMemoryWriter) error {
// Short circuit early if there are no precompile accepters to execute
if len(rules.AccepterPrecompiles) == 0 {
return nil
Expand Down
2 changes: 1 addition & 1 deletion plugin/evm/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func TestHandlePrecompileAccept(t *testing.T) {

// Call handlePrecompileAccept
blk := vm.newBlock(ethBlock)
rules := &params.Rules{
rules := params.Rules{
AccepterPrecompiles: map[common.Address]precompileconfig.Accepter{
precompileAddr: mockAccepter,
},
Expand Down
Loading

0 comments on commit 840876a

Please sign in to comment.