Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions cmd/XDC/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"errors"
"fmt"
"io"
"math/big"
"os"
"reflect"
"runtime"
Expand All @@ -43,7 +42,6 @@ import (
"github.com/XinFinOrg/XDPoSChain/log"
"github.com/XinFinOrg/XDPoSChain/metrics"
"github.com/XinFinOrg/XDPoSChain/node"
"github.com/XinFinOrg/XDPoSChain/params"
"github.com/naoina/toml"
"github.com/urfave/cli/v2"
)
Expand Down Expand Up @@ -163,15 +161,6 @@ func loadBaseConfig(ctx *cli.Context) XDCConfig {
common.Enable0xPrefix = false
}

// Check GasPrice
common.MinGasPrice = big.NewInt(common.DefaultMinGasPrice)
if ctx.IsSet(utils.MinerGasPriceFlag.Name) {
if gasPrice := int64(ctx.Int(utils.MinerGasPriceFlag.Name)); gasPrice > common.DefaultMinGasPrice {
common.MinGasPrice = big.NewInt(gasPrice)
}
}
params.SetMinGasPrice50x(common.MinGasPrice)

// read passwords from environment
passwords := []string{}
for _, env := range cfg.Account.Passwords {
Expand Down
2 changes: 0 additions & 2 deletions common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ var (

TRC21GasPriceBefore = big.NewInt(2500)
TRC21GasPrice = big.NewInt(250000000)
MinGasPrice = big.NewInt(250000000)
BaseFee = big.NewInt(12500000000)

// XDCx and XDCxlending
BasePrice = big.NewInt(1000000000000000000) // 1
Expand Down
19 changes: 13 additions & 6 deletions consensus/misc/eip1559/eip1559.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"fmt"
"math/big"

"github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/core/types"
"github.com/XinFinOrg/XDPoSChain/params"
)
Expand Down Expand Up @@ -56,12 +55,20 @@ func VerifyEip1559Header(config *params.ChainConfig, parent, header *types.Heade
return nil
}

// CalcBaseFee calculates the basefee of the header.
// CalcBaseFee computes the base fee for the block whose number is carried by header.
//
// NOTE: unlike upstream go-ethereum, header is the block being built or verified,
// not its parent. The XDC base fee does not depend on parent gas usage, but it is
// gas schedule aware, so passing a parent header yields the wrong tier on the
// block where a tier fork activates.
func CalcBaseFee(config *params.ChainConfig, header *types.Header) *big.Int {
// If the current block is the first EIP-1559 block, return the InitialBaseFee.
if config.IsEIP1559(header.Number) {
return new(big.Int).Set(common.BaseFee)
} else {
return CalcBaseFeeForBlockNumber(config, header.Number)
}

// CalcBaseFeeForBlockNumber computes the base fee for the given block number.
func CalcBaseFeeForBlockNumber(config *params.ChainConfig, number *big.Int) *big.Int {
if !config.IsEIP1559(number) {
return nil
}
return params.BaseFeeForBlock(config, number)
}
39 changes: 36 additions & 3 deletions consensus/misc/eip1559/eip1559_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"math/big"
"testing"

"github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/core/types"
"github.com/XinFinOrg/XDPoSChain/params"
)
Expand All @@ -31,6 +30,40 @@ func testConfigEip1559() *params.ChainConfig {
return &config
}

// TestCalcBaseFeeFollowsGasPriceSchedule pins the base fee returned for each
// tier of the gas price schedule.
func TestCalcBaseFeeFollowsGasPriceSchedule(t *testing.T) {
config := *params.TestChainConfig
config.EIP1559Block = big.NewInt(10)
config.Gas50xBlock = big.NewInt(0)
config.Gas2500xBlock = big.NewInt(20)

for _, tc := range []struct {
name string
block int64
want *big.Int
}{
{name: "before eip1559", block: 9, want: nil},
{name: "at eip1559", block: 10, want: big.NewInt(12_500_000_000)},
{name: "below gas2500x", block: 19, want: big.NewInt(12_500_000_000)},
{name: "at gas2500x", block: 20, want: big.NewInt(625_000_000_000)},
{name: "above gas2500x", block: 21, want: big.NewInt(625_000_000_000)},
} {
t.Run(tc.name, func(t *testing.T) {
got := CalcBaseFee(&config, &types.Header{Number: big.NewInt(tc.block)})
if tc.want == nil {
if got != nil {
t.Fatalf("expected nil base fee, got %v", got)
}
return
}
if got == nil || got.Cmp(tc.want) != 0 {
t.Fatalf("unexpected base fee: have %v want %v", got, tc.want)
}
})
}
}

func TestVerifyEip1559HeaderParentBaseFee(t *testing.T) {
config := testConfigEip1559()

Expand All @@ -52,7 +85,7 @@ func TestVerifyEip1559HeaderParentBaseFee(t *testing.T) {
name: "eip1559 parent with basefee",
parent: &types.Header{
Number: big.NewInt(1),
BaseFee: new(big.Int).Set(common.BaseFee),
BaseFee: new(big.Int).SetUint64(params.InitialBaseFee),
},
headerNum: 2,
wantOk: true,
Expand All @@ -68,7 +101,7 @@ func TestVerifyEip1559HeaderParentBaseFee(t *testing.T) {
} {
header := &types.Header{
Number: big.NewInt(tc.headerNum),
BaseFee: new(big.Int).Set(common.BaseFee),
BaseFee: new(big.Int).SetUint64(params.InitialBaseFee),
}
err := VerifyEip1559Header(config, tc.parent, header)
if tc.wantOk && err != nil {
Expand Down
2 changes: 1 addition & 1 deletion consensus/tests/engine_v1_tests/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ func createBlockFromHeader(bc *core.BlockChain, customHeader *types.Header, txs
Penalties: customHeader.Penalties,
}
if config != nil && config.IsEIP1559(header.Number) {
header.BaseFee = new(big.Int).Set(common.BaseFee)
header.BaseFee = params.BaseFeeForBlock(config, header.Number)
}
var block *types.Block
if len(txs) == 0 {
Expand Down
2 changes: 1 addition & 1 deletion consensus/tests/engine_v2_tests/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ func createBlockFromHeader(bc *core.BlockChain, customHeader *types.Header, txs
Penalties: customHeader.Penalties,
}
if config != nil && config.IsEIP1559(header.Number) {
header.BaseFee = new(big.Int).Set(common.BaseFee)
header.BaseFee = params.BaseFeeForBlock(config, header.Number)
}
var block *types.Block
if len(txs) == 0 {
Expand Down
2 changes: 1 addition & 1 deletion core/chainconfig_equal.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
// will stop matching the fast path and chainConfigJSONEqual will fall back to
// field-level semantic comparison until both sides are re-encoded. Update the
// pinned digest expectations in core/chainconfig_equal_test.go at the same time.
const chainConfigDigestVersion byte = 1
const chainConfigDigestVersion byte = 2

func defaultHashChainConfigSemanticVersioned(cfg *params.ChainConfig) (byte, [32]byte) {
return chainConfigDigestVersion, hashChainConfigSemantic(cfg)
Expand Down
9 changes: 5 additions & 4 deletions core/chainconfig_equal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var chainConfigDigestCoveredFields = []string{
"EIP158Block",
"EIP1559Block",
"Ethash",
"Gas2500xBlock",
"Gas50xBlock",
"HomesteadBlock",
"IstanbulBlock",
Expand Down Expand Up @@ -476,10 +477,10 @@ func TestHashChainConfigSemanticGoldenVectors(t *testing.T) {
cfg *params.ChainConfig
want string
}{
{name: "nil", cfg: nil, want: "47dc540c94ceb704a23875c11273e16bb0b8a87aed84de911f2133568115f254"},
{name: "testnet", cfg: params.TestnetChainConfig.Clone(), want: "211f23893f2d69fcca32285082e8ee73f4231786cf5e66f1d62cccfa295aad76"},
{name: "mainnet", cfg: params.XDCMainnetChainConfig.Clone(), want: "9076222c6783f37836c868190b78c7abe0b4d0d3fce93dc0aa12a6bc8b6ddcd3"},
{name: "testnet-berlin-drift", cfg: testnetBerlinDrift, want: "9711b6f1f09247c095eb193be8f24977ca706bd9fac1db2b1441a49c0dc3922a"},
{name: "nil", cfg: nil, want: "99be5efb88ca2013bd8e4eb035fd42d5245468fe9afa70d8ba9c1c419a48c4e8"},
{name: "testnet", cfg: params.TestnetChainConfig.Clone(), want: "759186a62685d424dc8ca52ff0db8e5e298c0e9341344b3142dfd43b743ddbb7"},
{name: "mainnet", cfg: params.XDCMainnetChainConfig.Clone(), want: "9b0ecfced732164016e61836ed57a626be9bffb3df283036e3337811a5feed3b"},
{name: "testnet-berlin-drift", cfg: testnetBerlinDrift, want: "6465ddb5a31a1b15c30479e666d10cec03dd4a862b372b3ff3a3961ad2134041"},
}

for _, test := range tests {
Expand Down
2 changes: 1 addition & 1 deletion core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ func (g *Genesis) toBlockWithRoot(root common.Hash) *types.Block {
if g.BaseFee != nil {
head.BaseFee = g.BaseFee
} else {
head.BaseFee = new(big.Int).SetUint64(params.InitialBaseFee)
head.BaseFee = params.BaseFeeForBlock(g.Config, common.Big0)
}
}
return types.NewBlock(head, nil, nil, trie.NewStackTrie(nil))
Expand Down
26 changes: 26 additions & 0 deletions core/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func TestCloneChainConfigDeepCopiesMigratedForkBlocks(t *testing.T) {
TIPXDCXCancellationFeeBlock: big.NewInt(70),
TIPTRC21FeeBlock: big.NewInt(75),
Gas50xBlock: big.NewInt(77),
Gas2500xBlock: big.NewInt(78),
BerlinBlock: big.NewInt(80),
LondonBlock: big.NewInt(90),
MergeBlock: big.NewInt(100),
Expand Down Expand Up @@ -213,6 +214,31 @@ func TestGenesisCopyDeepCopiesChainConfig(t *testing.T) {
}
}

func TestGenesisToBlockUsesScheduledBaseFeeAtGenesis(t *testing.T) {
genesis := &Genesis{
Config: &params.ChainConfig{
ChainID: big.NewInt(551),
TIPTRC21FeeBlock: big.NewInt(0),
Gas50xBlock: big.NewInt(0),
Gas2500xBlock: big.NewInt(0),
EIP1559Block: big.NewInt(0),
Ethash: new(params.EthashConfig),
},
Alloc: types.GenesisAlloc{common.Address{1}: {Balance: big.NewInt(1)}},
GasLimit: 4_700_000,
Difficulty: big.NewInt(1),
}

block, err := genesis.ToBlockWithError()
if err != nil {
t.Fatalf("ToBlockWithError failed: %v", err)
}
want := new(big.Int).SetUint64(common.DefaultMinGasPrice * 2500)
if got := block.BaseFee(); got == nil || got.Cmp(want) != 0 {
t.Fatalf("unexpected genesis base fee: have %v want %v", got, want)
}
}

// TestHydrateProvidedChainConfigPreservesEngineLessBuiltInTestNetwork tests hydrate provided chain config preserves engine less built in test network.
func TestHydrateProvidedChainConfigPreservesEngineLessBuiltInTestNetwork(t *testing.T) {
futureFork := big.NewInt(1_000_000_000)
Expand Down
2 changes: 1 addition & 1 deletion core/state_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ func GenerateBadBlock(t *testing.T, parent *types.Block, engine consensus.Engine
UncleHash: types.EmptyUncleHash,
}
if config.IsEIP1559(header.Number) {
header.BaseFee = common.BaseFee
header.BaseFee = params.BaseFeeForBlock(config, header.Number)
}
var receipts []*types.Receipt
// The post-state result doesn't need to be correct (this is a bad block), but we do need something there
Expand Down
29 changes: 15 additions & 14 deletions core/txpool/legacypool/legacypool.go
Original file line number Diff line number Diff line change
Expand Up @@ -1351,8 +1351,9 @@ func (pool *LegacyPool) runReorg(done chan struct{}, reset *txpoolResetRequest,
if reset != nil {
pool.demoteUnexecutables()
if reset.newHead != nil {
if pool.chainconfig.IsEIP1559(new(big.Int).Add(reset.newHead.Number, big.NewInt(1))) {
pendingBaseFee := eip1559.CalcBaseFee(pool.chainconfig, reset.newHead)
nextNumber := new(big.Int).Add(reset.newHead.Number, common.Big1)
if pool.chainconfig.IsEIP1559(nextNumber) {
pendingBaseFee := eip1559.CalcBaseFeeForBlockNumber(pool.chainconfig, nextNumber)
pool.priced.SetBaseFee(pendingBaseFee)
} else {
pool.priced.Reheap()
Expand Down Expand Up @@ -1495,12 +1496,12 @@ func (pool *LegacyPool) reset(oldHead, newHead *types.Header) {
// future queue to the set of pending transactions. During this process, all
// invalidated transactions (low nonce, low balance) are deleted.
func (pool *LegacyPool) promoteExecutables(accounts []common.Address) []*types.Transaction {
gasLimit := pool.currentHead.Load().GasLimit
var number *big.Int
if head := pool.chain.CurrentHeader(); head != nil {
number = head.Number
}
promotable, dropped, removedAddresses := pool.queue.promoteExecutables(accounts, gasLimit, pool.currentState, pool.pendingNonces, pool.trc21FeeCapacity, number, pool.chainconfig)
head := pool.currentHead.Load()
gasLimit := head.GasLimit
// Pooled txs can only be included from the next block onwards, so affordability
// checks below resolve the gas schedule at that height.
nextNumber := new(big.Int).Add(head.Number, common.Big1)
promotable, dropped, removedAddresses := pool.queue.promoteExecutables(accounts, gasLimit, pool.currentState, pool.pendingNonces, pool.trc21FeeCapacity, nextNumber, pool.chainconfig)

// promote all promotable transactions
promoted := make([]*types.Transaction, 0, len(promotable))
Expand Down Expand Up @@ -1636,7 +1637,11 @@ func (pool *LegacyPool) truncateQueue() {
// to trigger a re-heap is this function
func (pool *LegacyPool) demoteUnexecutables() {
// Iterate over all accounts and demote any non-executable transactions
gasLimit := pool.currentHead.Load().GasLimit
head := pool.currentHead.Load()
gasLimit := head.GasLimit
// Pending txs can only be included from the next block onwards, so affordability
// checks below resolve the gas schedule at that height.
nextNumber := new(big.Int).Add(head.Number, common.Big1)
for addr, list := range pool.pending {
nonce := pool.currentState.GetNonce(addr)

Expand All @@ -1648,11 +1653,7 @@ func (pool *LegacyPool) demoteUnexecutables() {
log.Trace("Removed old pending transaction", "hash", hash)
}
// Drop all transactions that are too costly (low balance or out of gas), and queue any invalids back for later
var number *big.Int = nil
if pool.chain.CurrentHeader() != nil {
number = pool.chain.CurrentHeader().Number
}
drops, invalids := list.Filter(pool.currentState.GetBalance(addr), gasLimit, pool.trc21FeeCapacity, number, pool.chainconfig)
drops, invalids := list.Filter(pool.currentState.GetBalance(addr), gasLimit, pool.trc21FeeCapacity, nextNumber, pool.chainconfig)
for _, tx := range drops {
hash := tx.Hash()
pool.all.Remove(hash)
Expand Down
Loading