Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] attempting to use uspstream blockchain.go for chain logic #676

Draft
wants to merge 43 commits into
base: libevm
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
314fe42
format: as subnet-evm
darioush Sep 25, 2024
72a4b00
take changes up to d72ff25 from subnet-evm
darioush Oct 2, 2024
b3647e3
complete use core/vm
darioush Sep 26, 2024
20754f7
format: as coreth
darioush Oct 2, 2024
6ff7f77
ci fixes
darioush Sep 26, 2024
512ae03
use race free version
darioush Sep 26, 2024
0baae1a
update version
darioush Sep 26, 2024
4fe802b
rebase new libevm
darioush Sep 27, 2024
df98c4e
remove WithExtras hack
darioush Oct 1, 2024
8e223b9
cleanup
darioush Oct 2, 2024
43dde81
fix genesis EthUpgrades
darioush Oct 3, 2024
0976d50
update libevm
darioush Oct 7, 2024
473a6ab
snapshot: initial refactoring for use with upstream statedb
darioush Oct 7, 2024
95c4c16
refactor: inline CommitWithSnap
darioush Oct 7, 2024
b82d5fa
remove unused args
darioush Oct 7, 2024
ac1e437
reduce diff
darioush Oct 7, 2024
2ebad51
handle snapshot update with root same as parent
darioush Oct 7, 2024
6b6fb64
reference root refactor (use triedb)
darioush Oct 8, 2024
b985d91
to fix on master
darioush Oct 8, 2024
87f64eb
nit: reduce diff w/ upstream
darioush Oct 8, 2024
e379625
no mc funds were used in genesis (mainnet/fuji)
darioush Oct 8, 2024
2d0ea28
minor improvement
darioush Oct 8, 2024
a963103
use libevm rebased for arr4n/state-db-extra-payload-handling
darioush Oct 8, 2024
dac5b3e
remove trie/ package
darioush Oct 8, 2024
27f02f1
use libevm for triedb
darioush Oct 9, 2024
4704b1c
update version e2e
darioush Oct 9, 2024
18d20f1
update geth packages
darioush Oct 9, 2024
1aa620e
remove triedb package
darioush Oct 9, 2024
d7bcf17
refactor: upstream types for snapshot and sync
darioush Oct 9, 2024
1cda8bb
use upstream statedb (embedded)
darioush Oct 9, 2024
0fa34e8
nit
darioush Oct 9, 2024
acacf56
unused
darioush Oct 9, 2024
747cb1d
fix e2e version
darioush Oct 9, 2024
f8a60f8
core: rename blockchain.go
darioush Oct 23, 2024
17f7c11
wip: adding blockchain.go as is (doesn't compile)
darioush Oct 23, 2024
6da51cf
wip: uses embedded for hc, and start/stops it
darioush Oct 23, 2024
25f4f0f
fixes: genesis TD, triedb writes, snapshot initialization
darioush Oct 24, 2024
a513c4e
stop acceptor before innner chain
darioush Oct 24, 2024
dfa4908
blockchain_ext.go: remove (some) unused code
darioush Oct 24, 2024
8da9955
blockchain_ext: remove quit chan
darioush Oct 24, 2024
d45a7dd
use reorg, and set preference logic from upstream, uses final block a…
darioush Oct 24, 2024
5573f27
handle stopInner after acceptor queue stop and CompareAndSwap
darioush Oct 24, 2024
fdb9494
blockchain_ext: remove unneeded fields
darioush Oct 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 3 additions & 3 deletions accounts/abi/bind/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ import (

"github.com/ava-labs/coreth/accounts/abi"
"github.com/ava-labs/coreth/core/types"
"github.com/ava-labs/coreth/core/vm"
"github.com/ava-labs/coreth/interfaces"
"github.com/ava-labs/coreth/nativeasset"
"github.com/ava-labs/coreth/rpc"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -308,14 +308,14 @@ func wrapNativeAssetCall(opts *TransactOpts, contract *common.Address, input []b
return nil, nil, errNativeAssetDeployContract
}
// wrap input with native asset call params
input = vm.PackNativeAssetCallInput(
input = nativeasset.PackNativeAssetCallInput(
*contract,
opts.NativeAssetCall.AssetID,
opts.NativeAssetCall.AssetAmount,
input,
)
// target addr is now precompile
contract = &vm.NativeAssetCallAddr
contract = &nativeasset.NativeAssetCallAddr
}
return contract, input, nil
}
Expand Down
6 changes: 3 additions & 3 deletions accounts/abi/bind/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ import (
"github.com/ava-labs/coreth/accounts/abi"
"github.com/ava-labs/coreth/accounts/abi/bind"
"github.com/ava-labs/coreth/core/types"
"github.com/ava-labs/coreth/core/vm"
"github.com/ava-labs/coreth/interfaces"
"github.com/ava-labs/coreth/nativeasset"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -404,8 +404,8 @@ func TestTransactNativeAssetCall(t *testing.T) {
nativeCallTx, err := bc.Transact(opts, methodName, arg1, arg2)
assert.Nil(err)
// verify transformations
assert.Equal(vm.NativeAssetCallAddr, *nativeCallTx.To())
unpackedAddr, unpackedAssetID, unpackedAssetAmount, unpackedData, err := vm.UnpackNativeAssetCallInput(nativeCallTx.Data())
assert.Equal(nativeasset.NativeAssetCallAddr, *nativeCallTx.To())
unpackedAddr, unpackedAssetID, unpackedAssetAmount, unpackedData, err := nativeasset.UnpackNativeAssetCallInput(nativeCallTx.Data())
assert.Nil(err)
assert.NotEmpty(unpackedData)
assert.Equal(unpackedData, normalCallTx.Data())
Expand Down
5 changes: 5 additions & 0 deletions accounts/abi/bind/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2179,6 +2179,11 @@ func golangBindings(t *testing.T, overload bool) {
if out, err := replacer.CombinedOutput(); err != nil {
t.Fatalf("failed to replace binding test dependency to current source tree: %v\n%s", err, out)
}
replacer = exec.Command(gocmd, "mod", "edit", "-x", "-require", "github.com/ethereum/[email protected]", "-replace", "github.com/ethereum/go-ethereum=github.com/ava-labs/[email protected]")
replacer.Dir = pkg
if out, err := replacer.CombinedOutput(); err != nil {
t.Fatalf("failed to replace binding test dependency to current source tree: %v\n%s", err, out)
}
tidier := exec.Command(gocmd, "mod", "tidy", "-compat=1.21")
tidier.Dir = pkg
if out, err := tidier.CombinedOutput(); err != nil {
Expand Down
9 changes: 7 additions & 2 deletions accounts/abi/bind/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,15 @@ func TestWaitDeployedCornerCases(t *testing.T) {
// Create a transaction to an account.
code := "6060604052600a8060106000396000f360606040526008565b00"
tx := types.NewTransaction(0, common.HexToAddress("0x01"), big.NewInt(0), 3000000, gasPrice, common.FromHex(code))
tx, _ = types.SignTx(tx, types.LatestSigner(params.TestChainConfig), testKey)
tx, err := types.SignTx(tx, types.LatestSignerForChainID(big.NewInt(1337)), testKey)
if err != nil {
t.Fatalf("Failed to sign transaction: %s", err)
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
backend.Client().SendTransaction(ctx, tx)
if err := backend.Client().SendTransaction(ctx, tx); err != nil {
t.Fatalf("Failed to send transaction: %s", err)
}
backend.Commit(true)
notContractCreation := errors.New("tx is not contract creation")
if _, err := bind.WaitDeployed(ctx, backend.Client(), tx); err.Error() != notContractCreation.Error() {
Expand Down
6 changes: 6 additions & 0 deletions consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ type Engine interface {
// header).
VerifyHeader(chain ChainHeaderReader, header *types.Header) error

// VerifyHeaders is similar to VerifyHeader, but verifies a batch of headers
// concurrently. The method returns a quit channel to abort the operations and
// a results channel to retrieve the async verifications (the order is that of
// the input slice).
VerifyHeaders(chain ChainHeaderReader, headers []*types.Header) (chan<- struct{}, <-chan error)

// VerifyUncles verifies that the given block's uncles conform to the consensus
// rules of a given engine.
VerifyUncles(chain ChainReader, block *types.Block) error
Expand Down
46 changes: 33 additions & 13 deletions consensus/dummy/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
"github.com/ava-labs/coreth/core/state"
"github.com/ava-labs/coreth/core/types"
"github.com/ava-labs/coreth/params"
"github.com/ava-labs/coreth/trie"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/trie"
)

var (
Expand Down Expand Up @@ -119,11 +119,11 @@ func (eng *DummyEngine) verifyHeaderGasFields(config *params.ChainConfig, header
if header.GasUsed > header.GasLimit {
return fmt.Errorf("invalid gasUsed: have %d, gasLimit %d", header.GasUsed, header.GasLimit)
}
if config.IsCortina(header.Time) {
if params.GetExtra(config).IsCortina(header.Time) {
if header.GasLimit != params.CortinaGasLimit {
return fmt.Errorf("expected gas limit to be %d in Cortina, but found %d", params.CortinaGasLimit, header.GasLimit)
}
} else if config.IsApricotPhase1(header.Time) {
} else if params.GetExtra(config).IsApricotPhase1(header.Time) {
if header.GasLimit != params.ApricotPhase1GasLimit {
return fmt.Errorf("expected gas limit to be %d in ApricotPhase1, but found %d", params.ApricotPhase1GasLimit, header.GasLimit)
}
Expand All @@ -140,7 +140,7 @@ func (eng *DummyEngine) verifyHeaderGasFields(config *params.ChainConfig, header
}
}

if !config.IsApricotPhase3(header.Time) {
if !params.GetExtra(config).IsApricotPhase3(header.Time) {
// Verify BaseFee is not present before AP3
if header.BaseFee != nil {
return fmt.Errorf("invalid baseFee before fork: have %d, want <nil>", header.BaseFee)
Expand All @@ -167,7 +167,7 @@ func (eng *DummyEngine) verifyHeaderGasFields(config *params.ChainConfig, header
}

// Verify BlockGasCost, ExtDataGasUsed not present before AP4
if !config.IsApricotPhase4(header.Time) {
if !params.GetExtra(config).IsApricotPhase4(header.Time) {
if header.BlockGasCost != nil {
return fmt.Errorf("invalid blockGasCost before fork: have %d, want <nil>", header.BlockGasCost)
}
Expand All @@ -179,7 +179,7 @@ func (eng *DummyEngine) verifyHeaderGasFields(config *params.ChainConfig, header

// Enforce BlockGasCost constraints
blockGasCostStep := ApricotPhase4BlockGasCostStep
if config.IsApricotPhase5(header.Time) {
if params.GetExtra(config).IsApricotPhase5(header.Time) {
blockGasCostStep = ApricotPhase5BlockGasCostStep
}
expectedBlockGasCost := calcBlockGasCost(
Expand Down Expand Up @@ -218,11 +218,11 @@ func (eng *DummyEngine) verifyHeader(chain consensus.ChainHeaderReader, header *
return errUnclesUnsupported
}
switch {
case config.IsDurango(header.Time):
case params.GetExtra(config).IsDurango(header.Time):
if len(header.Extra) < params.DynamicFeeExtraDataSize {
return fmt.Errorf("expected extra-data field length >= %d, found %d", params.DynamicFeeExtraDataSize, len(header.Extra))
}
case config.IsApricotPhase3(header.Time):
case params.GetExtra(config).IsApricotPhase3(header.Time):
if len(header.Extra) != params.DynamicFeeExtraDataSize {
return fmt.Errorf("expected extra-data field to be: %d, but found %d", params.DynamicFeeExtraDataSize, len(header.Extra))
}
Expand Down Expand Up @@ -299,6 +299,26 @@ func (eng *DummyEngine) VerifyHeader(chain consensus.ChainHeaderReader, header *
return eng.verifyHeader(chain, header, parent, false)
}

func (eng *DummyEngine) VerifyHeaders(
chain consensus.ChainHeaderReader, headers []*types.Header,
) (chan<- struct{}, <-chan error) {
abort := make(chan struct{})
results := make(chan error, len(headers))

go func() {
for _, header := range headers {
err := eng.VerifyHeader(chain, header) // XXX: Use provided parent for performance

select {
case <-abort:
return
case results <- err:
}
}
}()
return abort, results
}

func (*DummyEngine) VerifyUncles(chain consensus.ChainReader, block *types.Block) error {
if len(block.Uncles()) > 0 {
return errUnclesUnsupported
Expand Down Expand Up @@ -392,7 +412,7 @@ func (eng *DummyEngine) Finalize(chain consensus.ChainHeaderReader, block *types
return err
}
}
if chain.Config().IsApricotPhase4(block.Time()) {
if params.GetExtra(chain.Config()).IsApricotPhase4(block.Time()) {
// Validate extDataGasUsed and BlockGasCost match expectations
//
// NOTE: This is a duplicate check of what is already performed in
Expand All @@ -404,7 +424,7 @@ func (eng *DummyEngine) Finalize(chain consensus.ChainHeaderReader, block *types
return fmt.Errorf("invalid extDataGasUsed: have %d, want %d", blockExtDataGasUsed, extDataGasUsed)
}
blockGasCostStep := ApricotPhase4BlockGasCostStep
if chain.Config().IsApricotPhase5(block.Time()) {
if params.GetExtra(chain.Config()).IsApricotPhase5(block.Time()) {
blockGasCostStep = ApricotPhase5BlockGasCostStep
}
// Calculate the expected blockGasCost for this block.
Expand Down Expand Up @@ -450,13 +470,13 @@ func (eng *DummyEngine) FinalizeAndAssemble(chain consensus.ChainHeaderReader, h
return nil, err
}
}
if chain.Config().IsApricotPhase4(header.Time) {
if params.GetExtra(chain.Config()).IsApricotPhase4(header.Time) {
header.ExtDataGasUsed = extDataGasUsed
if header.ExtDataGasUsed == nil {
header.ExtDataGasUsed = new(big.Int).Set(common.Big0)
}
blockGasCostStep := ApricotPhase4BlockGasCostStep
if chain.Config().IsApricotPhase5(header.Time) {
if params.GetExtra(chain.Config()).IsApricotPhase5(header.Time) {
blockGasCostStep = ApricotPhase5BlockGasCostStep
}
// Calculate the required block gas cost for this block.
Expand Down Expand Up @@ -485,7 +505,7 @@ func (eng *DummyEngine) FinalizeAndAssemble(chain consensus.ChainHeaderReader, h
// Header seems complete, assemble into a block and return
return types.NewBlockWithExtData(
header, txs, uncles, receipts, trie.NewStackTrie(nil),
extraData, chain.Config().IsApricotPhase1(header.Time),
extraData, params.GetExtra(chain.Config()).IsApricotPhase1(header.Time),
), nil
}

Expand Down
10 changes: 5 additions & 5 deletions consensus/dummy/dynamic_fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ func CalcBaseFee(config *params.ChainConfig, parent *types.Header, timestamp uin
// If the current block is the first EIP-1559 block, or it is the genesis block
// return the initial slice and initial base fee.
var (
isApricotPhase3 = config.IsApricotPhase3(parent.Time)
isApricotPhase4 = config.IsApricotPhase4(parent.Time)
isApricotPhase5 = config.IsApricotPhase5(parent.Time)
isEtna = config.IsEtna(parent.Time)
isApricotPhase3 = params.GetExtra(config).IsApricotPhase3(parent.Time)
isApricotPhase4 = params.GetExtra(config).IsApricotPhase4(parent.Time)
isApricotPhase5 = params.GetExtra(config).IsApricotPhase5(parent.Time)
isEtna = params.GetExtra(config).IsEtna(parent.Time)
)
if !isApricotPhase3 || parent.Number.Cmp(common.Big0) == 0 {
initialSlice := make([]byte, params.DynamicFeeExtraDataSize)
Expand Down Expand Up @@ -332,7 +332,7 @@ func calcBlockGasCost(
//
// This function will return nil for all return values prior to Apricot Phase 4.
func MinRequiredTip(config *params.ChainConfig, header *types.Header) (*big.Int, error) {
if !config.IsApricotPhase4(header.Time) {
if !params.GetExtra(config).IsApricotPhase4(header.Time) {
return nil, nil
}
if header.BaseFee == nil {
Expand Down
2 changes: 1 addition & 1 deletion core/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ import (
"github.com/ava-labs/coreth/consensus/dummy"
"github.com/ava-labs/coreth/core/rawdb"
"github.com/ava-labs/coreth/core/types"
"github.com/ava-labs/coreth/core/vm"
"github.com/ava-labs/coreth/params"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
)
Expand Down
6 changes: 3 additions & 3 deletions core/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"github.com/ava-labs/coreth/core/state"
"github.com/ava-labs/coreth/core/types"
"github.com/ava-labs/coreth/params"
"github.com/ava-labs/coreth/trie"
"github.com/ethereum/go-ethereum/trie"
)

// BlockValidator is responsible for validating block headers, uncles and
Expand All @@ -43,12 +43,12 @@ import (
// BlockValidator implements Validator.
type BlockValidator struct {
config *params.ChainConfig // Chain configuration options
bc *BlockChain // Canonical block chain
bc *blockChain // Canonical block chain
engine consensus.Engine // Consensus engine used for validating
}

// NewBlockValidator returns a new block validator which is safe for re-use
func NewBlockValidator(config *params.ChainConfig, blockchain *BlockChain, engine consensus.Engine) *BlockValidator {
func NewBlockValidator(config *params.ChainConfig, blockchain *blockChain, engine consensus.Engine) *BlockValidator {
validator := &BlockValidator{
config: config,
engine: engine,
Expand Down
Loading
Loading