Skip to content

Commit

Permalink
update the constants for chain and dao
Browse files Browse the repository at this point in the history
  • Loading branch information
mapdev33 committed Jan 24, 2024
1 parent 5542471 commit 8820961
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 134 deletions.
14 changes: 7 additions & 7 deletions atlas/downloader/queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ package downloader

import (
"fmt"
"github.com/mapprotocol/atlas/consensus/consensustest"
chain2 "github.com/mapprotocol/atlas/core/chain"
params2 "github.com/mapprotocol/atlas/params"
"math/big"
"math/rand"
"sync"
"testing"
"time"

"github.com/mapprotocol/atlas/consensus/consensustest"
chain2 "github.com/mapprotocol/atlas/core/chain"
"github.com/mapprotocol/atlas/params"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/mapprotocol/atlas/core/rawdb"
"github.com/mapprotocol/atlas/core/types"
)
Expand All @@ -44,13 +44,13 @@ var (
// contains a transaction and every 5th an uncle to allow testing correct block
// reassembly.
func makeChain(n int, seed byte, parent *types.Block, empty bool) ([]*types.Block, []types.Receipts) {
blocks, receipts := chain2.GenerateChain(params2.TestChainConfig, parent, consensustest.NewFaker(), testdb, n, func(i int, block *chain2.BlockGen) {
blocks, receipts := chain2.GenerateChain(params.TestChainConfig, parent, consensustest.NewFaker(), testdb, n, func(i int, block *chain2.BlockGen) {
block.SetCoinbase(common.Address{seed})
// Add one tx to every secondblock
if !empty && i%2 == 0 {
signer := types.MakeSigner(params2.TestChainConfig, block.Number())
signer := types.MakeSigner(params.TestChainConfig, block.Number())
tx, err := types.SignTx(types.NewTransaction(block.TxNonce(testAddress), common.Address{seed},
big.NewInt(1000), params.TxGas, big.NewInt(100000000000), nil), signer, testKey)
big.NewInt(1000), params.TxGas, big.NewInt(100000000000), nil), signer, testKey)
if err != nil {
panic(err)
}
Expand Down
5 changes: 3 additions & 2 deletions atlas/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,23 @@
package atlas

import (
chain2 "github.com/mapprotocol/atlas/core/chain"
"math/big"
"sort"
"sync"

chain2 "github.com/mapprotocol/atlas/core/chain"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/params"
"github.com/mapprotocol/atlas/atlas/downloader"
"github.com/mapprotocol/atlas/core"
"github.com/mapprotocol/atlas/core/rawdb"
"github.com/mapprotocol/atlas/core/types"
"github.com/mapprotocol/atlas/core/vm"
"github.com/mapprotocol/atlas/params"
)

var (
Expand Down
7 changes: 3 additions & 4 deletions core/chain/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package chain
import (
"fmt"

ethparams "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/trie"

"github.com/mapprotocol/atlas/consensus"
Expand Down Expand Up @@ -109,10 +108,10 @@ func (v *BlockValidator) ValidateState(block *types.Block, statedb *state.StateD
// to keep the baseline gas close to the provided target, and increase it towards
// the target if the baseline gas is lower.
func CalcGasLimit(parentGasLimit, desiredLimit uint64) uint64 {
delta := parentGasLimit/ethparams.GasLimitBoundDivisor - 1
delta := parentGasLimit/params.GasLimitBoundDivisor - 1
limit := parentGasLimit
if desiredLimit < ethparams.MinGasLimit {
desiredLimit = ethparams.MinGasLimit
if desiredLimit < params.MinGasLimit {
desiredLimit = params.MinGasLimit
}
// If we're outside our allowed gas range, we try to hone towards them
if limit < desiredLimit {
Expand Down
3 changes: 1 addition & 2 deletions core/chain/blockchain_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"time"

"github.com/ethereum/go-ethereum/ethdb"
ethparams "github.com/ethereum/go-ethereum/params"

"github.com/mapprotocol/atlas/consensus"
"github.com/mapprotocol/atlas/consensus/consensustest"
Expand Down Expand Up @@ -73,7 +72,7 @@ func (basic *snapshotTestBasic) prepare(t *testing.T) (*BlockChain, []*types.Blo
}
// Initialize a fresh chain
var (
genesis = (&Genesis{BaseFee: big.NewInt(ethparams.InitialBaseFee)}).MustCommit(db)
genesis = (&Genesis{BaseFee: big.NewInt(params.InitialBaseFee)}).MustCommit(db)
engine = consensustest.NewFullFaker()
gendb = rawdb.NewMemoryDatabase()

Expand Down
122 changes: 61 additions & 61 deletions core/chain/blockchain_test.go

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions core/chain/chain_makers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ package chain

import (
"fmt"
"github.com/mapprotocol/atlas/core/abstract"
"math/big"

"github.com/mapprotocol/atlas/core/abstract"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethdb"
ethparams "github.com/ethereum/go-ethereum/params"

"github.com/mapprotocol/atlas/consensus"
"github.com/mapprotocol/atlas/consensus/misc"
Expand Down Expand Up @@ -206,12 +206,12 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse

// Mutate the state and block according to any hard-fork specs
if daoBlock := config.DAOForkBlock; daoBlock != nil {
limit := new(big.Int).Add(daoBlock, ethparams.DAOForkExtraRange)
if b.header.Number.Cmp(daoBlock) >= 0 && b.header.Number.Cmp(limit) < 0 {
if config.DAOForkSupport {
b.header.Extra = common.CopyBytes(ethparams.DAOForkBlockExtra)
}
}
// limit := new(big.Int).Add(daoBlock, ethparams.DAOForkExtraRange)
// if b.header.Number.Cmp(daoBlock) >= 0 && b.header.Number.Cmp(limit) < 0 {
// if config.DAOForkSupport {
// b.header.Extra = common.CopyBytes(ethparams.DAOForkBlockExtra)
// }
// }
}
if config.DAOForkSupport && config.DAOForkBlock != nil && config.DAOForkBlock.Cmp(b.header.Number) == 0 {
misc.ApplyDAOHardFork(statedb)
Expand Down Expand Up @@ -261,14 +261,14 @@ func makeHeader(chain consensus.ChainReader, parent *types.Block, state *state.S
Root: state.IntermediateRoot(chain.Config().IsEIP158(parent.Number())),
ParentHash: parent.Hash(),
Coinbase: parent.Coinbase(),
GasLimit: parent.GasLimit(),
Number: new(big.Int).Add(parent.Number(), common.Big1),
Time: time,
GasLimit: parent.GasLimit(),
Number: new(big.Int).Add(parent.Number(), common.Big1),
Time: time,
}
if chain.Config().IsLondon(header.Number) {
header.BaseFee = misc.CalcBaseFee(chain.Config(), parent.Header())
if !chain.Config().IsLondon(parent.Number()) {
parentGasLimit := parent.GasLimit() * ethparams.ElasticityMultiplier
parentGasLimit := parent.GasLimit() * params.ElasticityMultiplier
header.GasLimit = CalcGasLimit(parentGasLimit, parentGasLimit)
}
}
Expand Down
7 changes: 3 additions & 4 deletions core/chain/chain_makers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"math/big"

"github.com/ethereum/go-ethereum/crypto"
ethparams "github.com/ethereum/go-ethereum/params"

"github.com/mapprotocol/atlas/consensus/consensustest"
"github.com/mapprotocol/atlas/core/rawdb"
Expand Down Expand Up @@ -57,13 +56,13 @@ func ExampleGenerateChain() {
switch i {
case 0:
// In block 1, addr1 sends addr2 some ether.
tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(10000), ethparams.TxGas, nil, nil), signer, key1)
tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(10000), params.TxGas, nil, nil), signer, key1)
gen.AddTx(tx)
case 1:
// In block 2, addr1 sends some more ether to addr2.
// addr2 passes it on to addr3.
tx1, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(1000), ethparams.TxGas, nil, nil), signer, key1)
tx2, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr2), addr3, big.NewInt(1000), ethparams.TxGas, nil, nil), signer, key2)
tx1, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(1000), params.TxGas, nil, nil), signer, key1)
tx2, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr2), addr3, big.NewInt(1000), params.TxGas, nil, nil), signer, key2)
gen.AddTx(tx1)
gen.AddTx(tx2)
case 2:
Expand Down
4 changes: 1 addition & 3 deletions core/chain/dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
"math/big"
"testing"

ethparams "github.com/ethereum/go-ethereum/params"

"github.com/mapprotocol/atlas/consensus/consensustest"
"github.com/mapprotocol/atlas/core/rawdb"
"github.com/mapprotocol/atlas/core/vm"
Expand Down Expand Up @@ -67,7 +65,7 @@ func TestDAOForkRangeExtradata(t *testing.T) {
t.Fatalf("con-fork: failed to import chain prefix: %v", err)
}
// Try to expand both pro-fork and non-fork chains iteratively with other camp's blocks
for i := int64(0); i < ethparams.DAOForkExtraRange.Int64(); i++ {
for i := int64(0); i < params.DAOForkExtraRange.Int64(); i++ {
// Create a pro-fork block, and try to feed into the no-fork chain
db = rawdb.NewMemoryDatabase()
gspec.MustCommit(db)
Expand Down
22 changes: 11 additions & 11 deletions core/chain/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ import (
"encoding/json"
"errors"
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/rlp"
blscrypto "github.com/mapprotocol/atlas/helper/bls"
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log"
ethparams "github.com/ethereum/go-ethereum/params"
"github.com/mapprotocol/atlas/consensus"
"github.com/mapprotocol/atlas/core/rawdb"
"github.com/mapprotocol/atlas/core/state"
Expand Down Expand Up @@ -157,10 +157,10 @@ func (e *GenesisMismatchError) Error() string {
// SetupGenesisBlock writes or updates the genesis block in db.
// The block that will be used is:
//
// genesis == nil genesis != nil
// +------------------------------------------
// db has no genesis | main-net default | genesis
// db has genesis | from DB | genesis (if compatible)
// genesis == nil genesis != nil
// +------------------------------------------
// db has no genesis | main-net default | genesis
// db has genesis | from DB | genesis (if compatible)
//
// The stored chain configuration will be updated if it is compatible (i.e. does not
// specify a fork block below the local head block). In case of a conflict, the
Expand Down Expand Up @@ -315,13 +315,13 @@ func (g *Genesis) ToBlock(db ethdb.Database) *types.Block {
Root: root,
}
if head.GasLimit == 0 {
head.GasLimit = ethparams.GenesisGasLimit
head.GasLimit = params.GenesisGasLimit
}
if g.Config != nil && g.Config.IsLondon(common.Big0) {
if g.BaseFee != nil {
head.BaseFee = g.BaseFee
} else {
head.BaseFee = new(big.Int).SetUint64(ethparams.InitialBaseFee)
head.BaseFee = new(big.Int).SetUint64(params.InitialBaseFee)
}
}
statedb.Commit(false)
Expand Down Expand Up @@ -374,7 +374,7 @@ func (g *Genesis) MustCommit(db ethdb.Database) *types.Block {
func GenesisBlockForTesting(db ethdb.Database, addr common.Address, balance *big.Int) *types.Block {
g := Genesis{
Alloc: GenesisAlloc{addr: {Balance: balance}},
BaseFee: big.NewInt(ethparams.InitialBaseFee),
BaseFee: big.NewInt(params.InitialBaseFee),
}
return g.MustCommit(db)
}
Expand Down Expand Up @@ -429,8 +429,8 @@ func DefaultTestnetGenesisBlock() *Genesis {

// DevnetGenesisBlock returns the dev network genesis block.
// the keystore file is located in the keystore/devnet directory, the password for the keystore file is map123456
//prealloc address: 0x5F78EC486B721BAAE4aDD59A9bF3494C080A43C4
//priv: 939477962c734f29339531305a4309859aef4aa62e010529f3c343920ec1d49b
// prealloc address: 0x5F78EC486B721BAAE4aDD59A9bF3494C080A43C4
// priv: 939477962c734f29339531305a4309859aef4aa62e010529f3c343920ec1d49b
func DevnetGenesisBlock() *Genesis {
gs := genesisDevnetRegisterProxyContract()
balance0 := new(big.Int).Mul(big.NewInt(1000000000), big.NewInt(1e18))
Expand Down
25 changes: 12 additions & 13 deletions core/chain/state_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
ethparams "github.com/ethereum/go-ethereum/params"
"golang.org/x/crypto/sha3"

"github.com/mapprotocol/atlas/consensus"
Expand Down Expand Up @@ -59,14 +58,14 @@ func TestStateProcessorErrors(t *testing.T) {
}{
{
txs: []*types.Transaction{
makeTx(0, common.Address{}, big.NewInt(0), ethparams.TxGas, nil, nil),
makeTx(0, common.Address{}, big.NewInt(0), ethparams.TxGas, nil, nil),
makeTx(0, common.Address{}, big.NewInt(0), params.TxGas, nil, nil),
makeTx(0, common.Address{}, big.NewInt(0), params.TxGas, nil, nil),
},
want: "could not apply tx 1 [0x36bfa6d14f1cd35a1be8cc2322982a595fabc0e799f09c1de3bad7bd5b1f7626]: nonce too low: address 0x71562b71999873DB5b286dF957af199Ec94617F7, tx: 0 state: 1",
},
{
txs: []*types.Transaction{
makeTx(100, common.Address{}, big.NewInt(0), ethparams.TxGas, nil, nil),
makeTx(100, common.Address{}, big.NewInt(0), params.TxGas, nil, nil),
},
want: "could not apply tx 0 [0x51cd272d41ef6011d8138e18bf4043797aca9b713c7d39a97563f9bbe6bdbe6f]: nonce too high: address 0x71562b71999873DB5b286dF957af199Ec94617F7, tx: 100 state: 0",
},
Expand All @@ -78,22 +77,22 @@ func TestStateProcessorErrors(t *testing.T) {
},
{
txs: []*types.Transaction{
makeTx(0, common.Address{}, big.NewInt(1), ethparams.TxGas, nil, nil),
makeTx(0, common.Address{}, big.NewInt(1), params.TxGas, nil, nil),
},
want: "could not apply tx 0 [0x3094b17498940d92b13baccf356ce8bfd6f221e926abc903d642fa1466c5b50e]: insufficient funds for transfer: address 0x71562b71999873DB5b286dF957af199Ec94617F7",
},
{
txs: []*types.Transaction{
makeTx(0, common.Address{}, big.NewInt(0), ethparams.TxGas, big.NewInt(0xffffff), nil),
makeTx(0, common.Address{}, big.NewInt(0), params.TxGas, big.NewInt(0xffffff), nil),
},
want: "could not apply tx 0 [0xaa3f7d86802b1f364576d9071bf231e31d61b392d306831ac9cf706ff5371ce0]: insufficient funds for gas * price + value: address 0x71562b71999873DB5b286dF957af199Ec94617F7 have 0 want 352321515000",
},
{
txs: []*types.Transaction{
makeTx(0, common.Address{}, big.NewInt(0), ethparams.TxGas, nil, nil),
makeTx(1, common.Address{}, big.NewInt(0), ethparams.TxGas, nil, nil),
makeTx(2, common.Address{}, big.NewInt(0), ethparams.TxGas, nil, nil),
makeTx(3, common.Address{}, big.NewInt(0), ethparams.TxGas-1000, big.NewInt(0), nil),
makeTx(0, common.Address{}, big.NewInt(0), params.TxGas, nil, nil),
makeTx(1, common.Address{}, big.NewInt(0), params.TxGas, nil, nil),
makeTx(2, common.Address{}, big.NewInt(0), params.TxGas, nil, nil),
makeTx(3, common.Address{}, big.NewInt(0), params.TxGas-1000, big.NewInt(0), nil),
},
want: "could not apply tx 3 [0x836fab5882205362680e49b311a20646de03b630920f18ec6ee3b111a2cf6835]: intrinsic gas too low: have 20000, want 21000",
},
Expand All @@ -120,9 +119,9 @@ func GenerateBadBlock(parent *types.Block, engine consensus.Engine, txs types.Tr
header := &types.Header{
ParentHash: parent.Hash(),
Coinbase: parent.Coinbase(),
GasLimit: parent.GasLimit(),
Number: new(big.Int).Add(parent.Number(), common.Big1),
Time: parent.Time() + 10,
GasLimit: parent.GasLimit(),
Number: new(big.Int).Add(parent.Number(), common.Big1),
Time: parent.Time() + 10,
}
var receipts []*types.Receipt

Expand Down
22 changes: 12 additions & 10 deletions core/chain/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/ethereum/go-ethereum/common"
cmath "github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/params"
params "github.com/mapprotocol/atlas/params"

"github.com/mapprotocol/atlas/core"
"github.com/mapprotocol/atlas/core/types"
Expand All @@ -44,8 +44,10 @@ The state transitioning model does all the necessary work to work out a valid ne
3) Create a new state object if the recipient is \0*32
4) Value transfer
== If contract creation ==
4a) Attempt to run transaction data
4b) If valid, use result as code for the new state object
4a) Attempt to run transaction data
4b) If valid, use result as code for the new state object
== end ==
5) Run Script section
6) Derive new state root
Expand Down Expand Up @@ -262,13 +264,13 @@ func (st *StateTransition) preCheck() error {
// TransitionDb will transition the state by applying the current message and
// returning the evm execution result with following fields.
//
// - used gas:
// total gas used (including gas being refunded)
// - returndata:
// the returned data from evm
// - concrete execution error:
// various **EVM** error which aborts the execution,
// e.g. ErrOutOfGas, ErrExecutionReverted
// - used gas:
// total gas used (including gas being refunded)
// - returndata:
// the returned data from evm
// - concrete execution error:
// various **EVM** error which aborts the execution,
// e.g. ErrOutOfGas, ErrExecutionReverted
//
// However if any consensus issue encountered, return the error directly with
// nil evm execution result.
Expand Down
3 changes: 1 addition & 2 deletions core/chain/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/ethereum/go-ethereum/common/prque"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log"
ethparams "github.com/ethereum/go-ethereum/params"

"github.com/mapprotocol/atlas/consensus/misc"
"github.com/mapprotocol/atlas/contracts/blockchain_parameters"
Expand Down Expand Up @@ -95,7 +94,7 @@ var (
var (
evictionInterval = time.Minute // Time interval to check for evictable transactions
statsReportInterval = 8 * time.Second // Time interval to report transaction pool stats
defaultMinGasPrice = big.NewInt(100 * ethparams.GWei)
defaultMinGasPrice = big.NewInt(100 * params.GWei)
)

var (
Expand Down
Loading

0 comments on commit 8820961

Please sign in to comment.