Skip to content

Commit

Permalink
merge coreth 0.8.10-rc5 without fastsync & metrics package
Browse files Browse the repository at this point in the history
  • Loading branch information
ceyonur committed May 23, 2022
1 parent a531171 commit a1a05b2
Show file tree
Hide file tree
Showing 65 changed files with 503 additions and 4,265 deletions.
32 changes: 32 additions & 0 deletions .github/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: bug
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior.

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Logs**
If applicable, please include the relevant logs that indicate a problem and/or the log directory of your node. By default, this can be found at `~/.avalanchego/logs/`.

**Metrics**
If applicable, please include any metrics gathered from your node to assist us in diagnosing the problem.

**Operating System**
Which OS you used to reveal the bug.

**Additional context**
Add any other context about the problem here.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ WORKDIR /build
COPY go.mod go.sum avalanchego* ./

# Download avalanche dependencies using go mod
RUN go mod download
RUN go mod download && go mod tidy -compat=1.17

# Copy the code into the container
COPY . .
Expand Down
7 changes: 3 additions & 4 deletions accounts/abi/bind/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,6 @@ var bindTests = []struct {
},
// Tests that structs are correctly unpacked
{

`Structs`,
`
pragma solidity ^0.6.5;
Expand Down Expand Up @@ -2006,7 +2005,7 @@ func golangBindings(t *testing.T, overload bool) {
// defer os.RemoveAll(ws)

pkg := filepath.Join(ws, "bindtest")
if err = os.MkdirAll(pkg, 0700); err != nil {
if err = os.MkdirAll(pkg, 0o700); err != nil {
t.Fatalf("failed to create package: %v", err)
}
// Generate the test suite for all the contracts
Expand All @@ -2031,7 +2030,7 @@ func golangBindings(t *testing.T, overload bool) {
if err != nil {
t.Fatalf("test %d: failed to generate binding: %v", i, err)
}
if err = ioutil.WriteFile(filepath.Join(pkg, strings.ToLower(tt.name)+".go"), []byte(bind), 0600); err != nil {
if err = ioutil.WriteFile(filepath.Join(pkg, strings.ToLower(tt.name)+".go"), []byte(bind), 0o600); err != nil {
t.Fatalf("test %d: failed to write binding: %v", i, err)
}
// Generate the test file with the injected test code
Expand All @@ -2047,7 +2046,7 @@ func golangBindings(t *testing.T, overload bool) {
%s
}
`, tt.imports, tt.name, tt.tester)
if err := ioutil.WriteFile(filepath.Join(pkg, strings.ToLower(tt.name)+"_test.go"), []byte(code), 0600); err != nil {
if err := ioutil.WriteFile(filepath.Join(pkg, strings.ToLower(tt.name)+"_test.go"), []byte(code), 0o600); err != nil {
t.Fatalf("test %d: failed to write tests: %v", i, err)
}
})
Expand Down
40 changes: 0 additions & 40 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ import (
)

var (
removeTxIndicesKey = []byte("removed_tx_indices")

ErrRefuseToCorruptArchiver = errors.New("node has operated with pruning disabled, shutting down to prevent missing tries")

errFutureBlockUnsupported = errors.New("future block insertion not supported")
Expand Down Expand Up @@ -317,23 +315,6 @@ func (bc *BlockChain) loadLastState(lastAcceptedHash common.Hash) error {
return fmt.Errorf("could not load last accepted block")
}

// Remove all processing transaction indices leftover from when we used to
// write transaction indices as soon as a block was verified.
indicesRemoved, err := bc.db.Has(removeTxIndicesKey)
if err != nil {
return fmt.Errorf("unable to determine if transaction indices removed: %w", err)
}
if !indicesRemoved {
indicesRemoved, err := bc.removeIndices(currentBlock.NumberU64(), bc.lastAccepted.NumberU64())
if err != nil {
return err
}
if err := bc.db.Put(removeTxIndicesKey, bc.lastAccepted.Number().Bytes()); err != nil {
return fmt.Errorf("unable to mark indices removed: %w", err)
}
log.Debug("removed processing transaction indices", "count", indicesRemoved, "currentBlock", currentBlock.NumberU64(), "lastAccepted", bc.lastAccepted.NumberU64())
}

// This ensures that the head block is updated to the last accepted block on startup
if err := bc.setPreference(bc.lastAccepted); err != nil {
return fmt.Errorf("failed to set preference to last accepted block while loading last state: %w", err)
Expand All @@ -345,27 +326,6 @@ func (bc *BlockChain) loadLastState(lastAcceptedHash common.Hash) error {
return bc.reprocessState(bc.lastAccepted, 2*commitInterval)
}

// removeIndices removes all transaction lookup entries for the transactions contained in the canonical chain
// from block at height [to] to block at height [from]. Blocks are traversed in reverse order.
func (bc *BlockChain) removeIndices(from, to uint64) (int, error) {
indicesRemoved := 0
batch := bc.db.NewBatch()
for i := from; i > to; i-- {
b := bc.GetBlockByNumber(i)
if b == nil {
return indicesRemoved, fmt.Errorf("could not load canonical block at height %d", i)
}
for _, tx := range b.Transactions() {
rawdb.DeleteTxLookupEntry(batch, tx.Hash())
indicesRemoved++
}
}
if err := batch.Write(); err != nil {
return 0, fmt.Errorf("failed to write batch while removing indices (from: %d, to: %d): %w", from, to, err)
}
return indicesRemoved, nil
}

func (bc *BlockChain) loadGenesisState() error {
// Prepare the genesis block and reinitialise the chain
batch := bc.db.NewBatch()
Expand Down
8 changes: 5 additions & 3 deletions core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,11 @@ func SetupGenesisBlock(db ethdb.Database, genesis *Genesis) (*params.ChainConfig
return nil, errGenesisNoConfig
}
// Make sure genesis gas limit is consistent
gasLimitConfig := genesis.Config.FeeConfig.GasLimit.Uint64()
if gasLimitConfig != genesis.GasLimit {
return nil, fmt.Errorf("gas limit in fee config (%d) does not match gas limit in header (%d)", gasLimitConfig, genesis.GasLimit)
if genesis.Config.IsSubnetEVM(common.Big0) {
gasLimitConfig := genesis.Config.FeeConfig.GasLimit.Uint64()
if gasLimitConfig != genesis.GasLimit {
return nil, fmt.Errorf("gas limit in fee config (%d) does not match gas limit in header (%d)", gasLimitConfig, genesis.GasLimit)
}
}
// Just commit the new block if there is no stored genesis block.
stored := rawdb.ReadCanonicalHash(db, 0)
Expand Down
5 changes: 5 additions & 0 deletions core/state_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,17 @@ package core
import (
"fmt"
"math/rand"
"time"

"github.com/ava-labs/subnet-evm/core/types"
"github.com/ava-labs/subnet-evm/ethdb"
"github.com/ethereum/go-ethereum/common"
)

func init() {
rand.Seed(time.Now().UnixNano())
}

const (
commitInterval = 4096
tipBufferSize = 32
Expand Down
40 changes: 20 additions & 20 deletions core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -663,15 +663,31 @@ func (pool *TxPool) local() map[common.Address]types.Transactions {
return txs
}

func (pool *TxPool) CheckNonceOrdering(from common.Address, txNonce uint64) error {
// checks transaction validity against the current state.
func (pool *TxPool) checkTxState(from common.Address, tx *types.Transaction) error {
pool.currentStateLock.Lock()
defer pool.currentStateLock.Unlock()

// cost == V + GP * GL
if balance, cost := pool.currentState.GetBalance(from), tx.Cost(); balance.Cmp(cost) < 0 {
return fmt.Errorf("%w: address %s have (%d) want (%d)", ErrInsufficientFunds, from.Hex(), balance, cost)
}

txNonce := tx.Nonce()
// Ensure the transaction adheres to nonce ordering
if currentNonce, txNonce := pool.currentState.GetNonce(from), txNonce; currentNonce > txNonce {
if currentNonce := pool.currentState.GetNonce(from); currentNonce > txNonce {
return fmt.Errorf("%w: address %s current nonce (%d) > tx nonce (%d)",
ErrNonceTooLow, from.Hex(), currentNonce, txNonce)
}
isTxAllowList := pool.chainconfig.IsTxAllowList(pool.currentHead.Number)

// If the tx allow list is enabled, return an error if the from address is not allow listed.
if isTxAllowList {
txAllowListRole := precompile.GetTxAllowListStatus(pool.currentState, from)
if !txAllowListRole.IsEnabled() {
return fmt.Errorf("%w: %s", precompile.ErrSenderAddressNotAllowListed, from)
}
}
return nil
}

Expand Down Expand Up @@ -723,28 +739,12 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
if pool.minimumFee != nil && tx.GasFeeCapIntCmp(pool.minimumFee) < 0 {
return fmt.Errorf("%w: address %s have gas fee cap (%d) < pool minimum fee cap (%d)", ErrUnderpriced, from.Hex(), tx.GasFeeCap(), pool.minimumFee)
}

// Ensure the transaction adheres to nonce ordering
if err := pool.CheckNonceOrdering(from, tx.Nonce()); err != nil {
if err := pool.checkTxState(from, tx); err != nil {
return err
}

isTxAllowList := pool.chainconfig.IsTxAllowList(pool.currentHead.Number)
// Transactor should have enough funds to cover the costs
// cost == V + GP * GL
pool.currentStateLock.Lock()
if balance, cost := pool.currentState.GetBalance(from), tx.Cost(); balance.Cmp(cost) < 0 {
pool.currentStateLock.Unlock()
return fmt.Errorf("%w: address %s have (%d) want (%d)", ErrInsufficientFunds, from.Hex(), balance, cost)
}
// If the tx allow list is enabled, return an error if the from address is not allow listed.
if isTxAllowList {
txAllowListRole := precompile.GetTxAllowListStatus(pool.currentState, from)
if !txAllowListRole.IsEnabled() {
pool.currentStateLock.Unlock()
return fmt.Errorf("%w: %s", precompile.ErrSenderAddressNotAllowListed, from)
}
}
pool.currentStateLock.Unlock()
// Ensure the transaction has more gas than the basic tx fee.
intrGas, err := IntrinsicGas(tx.Data(), tx.AccessList(), tx.To() == nil, true, pool.istanbul)
if err != nil {
Expand Down
Loading

0 comments on commit a1a05b2

Please sign in to comment.