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

Sync coreth v0.12.4 rc0 #694

Merged
merged 45 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
446d9b0
apply diff to rc0
ceyonur Jun 20, 2023
4781e33
replace coreth with subnet-evm
ceyonur Jun 20, 2023
a3035e8
go mod tidy
ceyonur Jun 20, 2023
615175d
remove must commit
ceyonur Jun 20, 2023
ae82208
remove apricots
ceyonur Jun 20, 2023
bfdcbf0
replace coreth with subnet-evm
ceyonur Jun 20, 2023
6f6b384
rename banff and cortina
ceyonur Jun 20, 2023
e1452e6
test memory db
ceyonur Jun 20, 2023
e59384f
add dUpgrade
ceyonur Jun 20, 2023
ad6362f
fix errors
ceyonur Jun 22, 2023
592fab9
sync with v0.12.4-rc0
ceyonur Jun 22, 2023
e3bf60b
more diffs
ceyonur Jun 22, 2023
e6ae83d
change templates
ceyonur Jun 22, 2023
2096ec4
readd preparePredicateSlots
ceyonur Jun 22, 2023
efd6b54
run goimports
ceyonur Jun 23, 2023
c483d48
readd tx allow list check to txpool
ceyonur Jun 26, 2023
07cee0c
Fix tests
ceyonur Jun 26, 2023
584a070
readd subnet evm check for tests
ceyonur Jun 30, 2023
0ee34fa
fix tests
ceyonur Jun 30, 2023
a637121
add gas limit & coinbase fakers
ceyonur Jun 30, 2023
0d79a26
Merge branch 'master' into sync-coreth-v0.12.4-rc0
ceyonur Jun 30, 2023
f91ed29
Merge branch 'master' into sync-coreth-v0.12.4-rc0
ceyonur Jul 4, 2023
53c40df
Fix timestamp types
ceyonur Jul 4, 2023
72e81d7
check error from newblockchain
ceyonur Jul 4, 2023
3983d73
fix gas limit in simulated genesis
ceyonur Jul 4, 2023
7bd29de
downgrade ci to go 1.19
ceyonur Jul 4, 2023
e614085
gofmt files
ceyonur Jul 4, 2023
a5e4bd2
Merge branch 'sync-coreth-v0.12.4-rc0' of github.com:ava-labs/subnet-…
ceyonur Jul 4, 2023
54ca59c
rebump go to 1.20
ceyonur Jul 4, 2023
203195a
bump anr to latest
ceyonur Jul 4, 2023
f939962
bump anr to latest
ceyonur Jul 4, 2023
03d6889
Merge branch 'sync-coreth-v0.12.4-rc0' of github.com:ava-labs/subnet-…
ceyonur Jul 4, 2023
92d3973
prepare predicate storage slots in Subnet-EVM
ceyonur Jul 6, 2023
1e3f403
uncomment tests
ceyonur Jul 10, 2023
6dc9788
change order of airdrop memory cleanup
ceyonur Jul 14, 2023
1dc0a96
Merge branch 'master' into sync-coreth-v0.12.4-rc0
ceyonur Jul 18, 2023
bc50ccf
add utils import
ceyonur Jul 20, 2023
2b6cd7e
Coreth 0.12.4 x apply (#720)
ceyonur Jul 21, 2023
3e38277
move instruction sets
ceyonur Jul 21, 2023
900eb39
revert unpack changes
ceyonur Jul 21, 2023
935d9a6
Merge branch 'master' into sync-coreth-v0.12.4-rc0
ceyonur Jul 24, 2023
7b6fc53
reduce diffs
ceyonur Jul 24, 2023
fba21c6
move genesis verify to vm (#753)
ceyonur Jul 25, 2023
14bf3a8
avoid adding/removing GasLimits in tests (#755)
darioush Jul 25, 2023
2f1c726
Merge branch 'master' into sync-coreth-v0.12.4-rc0
ceyonur Jul 26, 2023
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 .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
shell: bash
- uses: actions/setup-go@v3
with:
go-version: "1.19"
go-version: "1.20"
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
Expand All @@ -33,7 +33,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: "1.19"
go-version: "1.20"
- run: go mod download
shell: bash
- run: ./scripts/build.sh ./build/subnetevm
Expand Down Expand Up @@ -64,7 +64,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: "1.19"
go-version: "1.20"
- name: Use Node.js
uses: actions/setup-node@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
ARG AVALANCHE_VERSION

# ============= Compilation Stage ================
FROM golang:1.19.6-buster AS builder
FROM golang:1.20.1-buster AS builder
RUN apt-get update && apt-get install -y --no-install-recommends bash=5.0-4 make=4.2.1-1.2 gcc=4:8.3.0-1 musl-dev=1.1.21-2 ca-certificates=20200601~deb10u2 linux-headers-amd64

WORKDIR /build
Expand Down
2 changes: 1 addition & 1 deletion accounts/abi/abi.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (abi ABI) getArguments(name string, data []byte) (Arguments, error) {
var args Arguments
if method, ok := abi.Methods[name]; ok {
if len(data)%32 != 0 {
return nil, fmt.Errorf("abi: improperly formatted output: %s - Bytes: [%+v]", string(data), data)
return nil, fmt.Errorf("abi: improperly formatted output: %q - Bytes: %+v", data, data)
}
args = method.Outputs
}
Expand Down
12 changes: 6 additions & 6 deletions accounts/abi/abi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -738,12 +738,12 @@ func TestBareEvents(t *testing.T) {
// TestUnpackEvent is based on this contract:
//
// contract T {
// event received(address sender, uint amount, bytes memo);
// event receivedAddr(address sender);
// function receive(bytes memo) external payable {
// received(msg.sender, msg.value, memo);
// receivedAddr(msg.sender);
// }
// event received(address sender, uint amount, bytes memo);
// event receivedAddr(address sender);
// function receive(bytes memo) external payable {
// received(msg.sender, msg.value, memo);
// receivedAddr(msg.sender);
// }
// }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I'm seeing some more spacing fixes on this file

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

//
// When receive("X") is called with sender 0x00... and value 1, it produces this tx receipt:
Expand Down
117 changes: 77 additions & 40 deletions accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,20 @@ type SimulatedBackend struct {
// and uses a simulated blockchain for testing purposes.
// A simulated backend always uses chainID 1337.
func NewSimulatedBackendWithDatabase(database ethdb.Database, alloc core.GenesisAlloc, gasLimit uint64) *SimulatedBackend {
genesis := core.Genesis{Config: params.SimulatedTestChainConfig, GasLimit: gasLimit, Alloc: alloc}
genesis.MustCommit(database)
cpcfg := params.SimulatedTestChainConfig
if cpcfg.FeeConfig.GasLimit.Uint64() != gasLimit {
cpcfg.FeeConfig.GasLimit = big.NewInt(int64(gasLimit))
}
genesis := core.Genesis{
Config: params.SimulatedTestChainConfig,
GasLimit: gasLimit,
Alloc: alloc,
}
cacheConfig := &core.CacheConfig{}
blockchain, _ := core.NewBlockChain(database, cacheConfig, genesis.Config, dummy.NewCoinbaseFaker(), vm.Config{}, common.Hash{})

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))
}
backend := &SimulatedBackend{
database: database,
blockchain: blockchain,
Expand All @@ -120,9 +129,12 @@ func NewSimulatedBackendWithDatabase(database ethdb.Database, alloc core.Genesis

filterBackend := &filterBackend{database, blockchain, backend}
backend.filterSystem = filters.NewFilterSystem(filterBackend, filters.Config{})
backend.events = filters.NewEventSystem(backend.filterSystem, false)
backend.events = filters.NewEventSystem(backend.filterSystem)

header := backend.blockchain.CurrentBlock()
block := backend.blockchain.GetBlock(header.Hash(), header.Number.Uint64())

backend.rollback(blockchain.CurrentBlock())
backend.rollback(block)
return backend
}

Expand Down Expand Up @@ -168,7 +180,10 @@ func (b *SimulatedBackend) Rollback() {
b.mu.Lock()
defer b.mu.Unlock()

b.rollback(b.blockchain.CurrentBlock())
header := b.blockchain.CurrentBlock()
block := b.blockchain.GetBlock(header.Hash(), header.Number.Uint64())

b.rollback(block)
}

func (b *SimulatedBackend) rollback(parent *types.Block) {
Expand Down Expand Up @@ -207,7 +222,7 @@ func (b *SimulatedBackend) Fork(ctx context.Context, parent common.Hash) error {

// stateByBlockNumber retrieves a state by a given blocknumber.
func (b *SimulatedBackend) stateByBlockNumber(ctx context.Context, blockNumber *big.Int) (*state.StateDB, error) {
if blockNumber == nil || blockNumber.Cmp(b.blockchain.CurrentBlock().Number()) == 0 {
if blockNumber == nil || blockNumber.Cmp(b.blockchain.CurrentBlock().Number) == 0 {
return b.blockchain.State()
}
block, err := b.blockByNumber(ctx, blockNumber)
Expand Down Expand Up @@ -336,7 +351,7 @@ func (b *SimulatedBackend) BlockByNumber(ctx context.Context, number *big.Int) (
// (associated with its hash) if found without Lock.
func (b *SimulatedBackend) blockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) {
if number == nil || number.Cmp(b.acceptedBlock.Number()) == 0 {
return b.blockchain.CurrentBlock(), nil
return b.blockByHash(ctx, b.blockchain.CurrentBlock().Hash())
}

block := b.blockchain.GetBlockByNumber(uint64(number.Int64()))
Expand Down Expand Up @@ -464,7 +479,7 @@ func (b *SimulatedBackend) CallContract(ctx context.Context, call interfaces.Cal
b.mu.Lock()
defer b.mu.Unlock()

if blockNumber != nil && blockNumber.Cmp(b.blockchain.CurrentBlock().Number()) != 0 {
if blockNumber != nil && blockNumber.Cmp(b.blockchain.CurrentBlock().Number) != 0 {
return nil, errBlockNumberUnsupported
}
stateDB, err := b.blockchain.State()
Expand All @@ -488,7 +503,7 @@ func (b *SimulatedBackend) AcceptedCallContract(ctx context.Context, call interf
defer b.mu.Unlock()
defer b.acceptedState.RevertToSnapshot(b.acceptedState.Snapshot())

res, err := b.callContract(ctx, call, b.acceptedBlock, b.acceptedState)
res, err := b.callContract(ctx, call, b.acceptedBlock.Header(), b.acceptedState)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -560,7 +575,7 @@ func (b *SimulatedBackend) EstimateGas(ctx context.Context, call interfaces.Call
available := new(big.Int).Set(balance)
if call.Value != nil {
if call.Value.Cmp(available) >= 0 {
return 0, errors.New("insufficient funds for transfer")
return 0, core.ErrInsufficientFundsForTransfer
}
available.Sub(available, call.Value)
}
Expand All @@ -582,7 +597,7 @@ func (b *SimulatedBackend) EstimateGas(ctx context.Context, call interfaces.Call
call.Gas = gas

snapshot := b.acceptedState.Snapshot()
res, err := b.callContract(ctx, call, b.acceptedBlock, b.acceptedState)
res, err := b.callContract(ctx, call, b.acceptedBlock.Header(), b.acceptedState)
b.acceptedState.RevertToSnapshot(snapshot)

if err != nil {
Expand Down Expand Up @@ -631,13 +646,13 @@ func (b *SimulatedBackend) EstimateGas(ctx context.Context, call interfaces.Call

// callContract implements common code between normal and pending contract calls.
// state is modified during execution, make sure to copy it if necessary.
func (b *SimulatedBackend) callContract(ctx context.Context, call interfaces.CallMsg, block *types.Block, stateDB *state.StateDB) (*core.ExecutionResult, error) {
func (b *SimulatedBackend) callContract(ctx context.Context, call interfaces.CallMsg, header *types.Header, stateDB *state.StateDB) (*core.ExecutionResult, error) {
// Gas prices post 1559 need to be initialized
if call.GasPrice != nil && (call.GasFeeCap != nil || call.GasTipCap != nil) {
return nil, errors.New("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified")
}
head := b.blockchain.CurrentHeader()
if !b.blockchain.Config().IsSubnetEVM(new(big.Int).SetUint64(head.Time)) {
if !b.blockchain.Config().IsSubnetEVM(head.Time) {
// If there's no basefee, then it must be a non-1559 execution
if call.GasPrice == nil {
call.GasPrice = new(big.Int)
Expand Down Expand Up @@ -670,20 +685,33 @@ func (b *SimulatedBackend) callContract(ctx context.Context, call interfaces.Cal
if call.Value == nil {
call.Value = new(big.Int)
}

// Set infinite balance to the fake caller account.
from := stateDB.GetOrNewStateObject(call.From)
from.SetBalance(math.MaxBig256)

// Execute the call.
msg := callMsg{call}
msg := &core.Message{
From: call.From,
To: call.To,
Value: call.Value,
GasLimit: call.Gas,
GasPrice: call.GasPrice,
GasFeeCap: call.GasFeeCap,
GasTipCap: call.GasTipCap,
Data: call.Data,
AccessList: call.AccessList,
SkipAccountChecks: true,
}

txContext := core.NewEVMTxContext(msg)
evmContext := core.NewEVMBlockContext(block.Header(), b.blockchain, nil)
// Create a new environment which holds all relevant information
// about the transaction and calling mechanisms.
txContext := core.NewEVMTxContext(msg)
evmContext := core.NewEVMBlockContext(header, b.blockchain, nil)
vmEnv := vm.NewEVM(evmContext, txContext, stateDB, b.config, vm.Config{NoBaseFee: true})
gasPool := new(core.GasPool).AddGas(math.MaxUint64)

return core.NewStateTransition(vmEnv, msg, gasPool).TransitionDb()
return core.ApplyMessage(vmEnv, msg, gasPool)
}

// SendTransaction updates the pending block to include the given transaction.
Expand Down Expand Up @@ -827,8 +855,12 @@ func (b *SimulatedBackend) AdjustTime(adjustment time.Duration) error {
if len(b.acceptedBlock.Transactions()) != 0 {
return errors.New("Could not adjust time on non-empty block")
}
block := b.blockchain.GetBlockByHash(b.acceptedBlock.ParentHash())
if block == nil {
return fmt.Errorf("could not find parent")
}

blocks, _, _ := core.GenerateChain(b.config, b.blockchain.CurrentBlock(), dummy.NewFaker(), b.database, 1, 10, func(number int, block *core.BlockGen) {
blocks, _, _ := core.GenerateChain(b.config, block, dummy.NewFaker(), b.database, 1, 10, func(number int, block *core.BlockGen) {
block.OffsetTime(int64(adjustment.Seconds()))
})
stateDB, _ := b.blockchain.State()
Expand All @@ -844,23 +876,6 @@ func (b *SimulatedBackend) Blockchain() *core.BlockChain {
return b.blockchain
}

// callMsg implements core.Message to allow passing it as a transaction simulator.
type callMsg struct {
interfaces.CallMsg
}

func (m callMsg) From() common.Address { return m.CallMsg.From }
func (m callMsg) Nonce() uint64 { return 0 }
func (m callMsg) IsFake() bool { return true }
func (m callMsg) To() *common.Address { return m.CallMsg.To }
func (m callMsg) GasPrice() *big.Int { return m.CallMsg.GasPrice }
func (m callMsg) GasFeeCap() *big.Int { return m.CallMsg.GasFeeCap }
func (m callMsg) GasTipCap() *big.Int { return m.CallMsg.GasTipCap }
func (m callMsg) Gas() uint64 { return m.CallMsg.Gas }
func (m callMsg) Value() *big.Int { return m.CallMsg.Value }
func (m callMsg) Data() []byte { return m.CallMsg.Data }
func (m callMsg) AccessList() types.AccessList { return m.CallMsg.AccessList }

// filterBackend implements filters.Backend to support filtering for logs without
// taking bloom-bits acceleration structures into account.
type filterBackend struct {
Expand Down Expand Up @@ -897,17 +912,31 @@ func (fb *filterBackend) ChainDb() ethdb.Database { return fb.db }

func (fb *filterBackend) EventMux() *event.TypeMux { panic("not supported") }

func (fb *filterBackend) HeaderByNumber(ctx context.Context, block rpc.BlockNumber) (*types.Header, error) {
if block == rpc.LatestBlockNumber {
func (fb *filterBackend) HeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Header, error) {
switch number {
case rpc.PendingBlockNumber, rpc.AcceptedBlockNumber:
if block := fb.backend.acceptedBlock; block != nil {
return block.Header(), nil
}
return nil, nil
case rpc.LatestBlockNumber:
return fb.bc.CurrentHeader(), nil
default:
return fb.bc.GetHeaderByNumber(uint64(number.Int64())), nil
}
return fb.bc.GetHeaderByNumber(uint64(block.Int64())), nil
}

func (fb *filterBackend) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) {
return fb.bc.GetHeaderByHash(hash), nil
}

func (fb *filterBackend) GetBody(ctx context.Context, hash common.Hash, number rpc.BlockNumber) (*types.Body, error) {
if body := fb.bc.GetBody(hash); body != nil {
return body, nil
}
return nil, errors.New("block body not found")
}

func (fb *filterBackend) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) {
number := rawdb.ReadHeaderNumber(fb.db, hash)
if number == nil {
Expand Down Expand Up @@ -947,6 +976,14 @@ func (fb *filterBackend) ServiceFilter(ctx context.Context, ms *bloombits.Matche
panic("not supported")
}

func (fb *filterBackend) ChainConfig() *params.ChainConfig {
panic("not supported")
}

func (fb *filterBackend) CurrentHeader() *types.Header {
panic("not supported")
}

func nullSubscription() event.Subscription {
return event.NewSubscription(func(quit <-chan struct{}) error {
<-quit
Expand Down
Loading