Skip to content

Commit

Permalink
update the constants for abi and atlas
Browse files Browse the repository at this point in the history
  • Loading branch information
mapdev33 committed Jan 24, 2024
1 parent aaa9aa0 commit 14bfb03
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 77 deletions.
7 changes: 3 additions & 4 deletions apis/atlasapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
ethparams "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rpc"
"github.com/tyler-smith/go-bip39"
Expand Down Expand Up @@ -940,7 +939,7 @@ func (s *PublicBlockChainAPI) Call(ctx context.Context, args TransactionArgs, bl
func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, gasCap uint64) (hexutil.Uint64, error) {
// Binary search the gas requirement, as it may be higher than the amount used
var (
lo uint64 = ethparams.TxGas - 1
lo uint64 = params.TxGas - 1
hi uint64
cap uint64
)
Expand All @@ -949,7 +948,7 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr
args.From = new(common.Address)
}
// Determine the highest gas limit can be used during the estimation.
if args.Gas != nil && uint64(*args.Gas) >= ethparams.TxGas {
if args.Gas != nil && uint64(*args.Gas) >= params.TxGas {
hi = uint64(*args.Gas)
} else {
// Retrieve the block to act as the gas ceiling
Expand Down Expand Up @@ -2031,7 +2030,7 @@ func checkTxFee(gasPrice *big.Int, gas uint64, cap float64) error {
if cap == 0 {
return nil
}
feeEth := new(big.Float).Quo(new(big.Float).SetInt(new(big.Int).Mul(gasPrice, new(big.Int).SetUint64(gas))), new(big.Float).SetInt(big.NewInt(ethparams.Ether)))
feeEth := new(big.Float).Quo(new(big.Float).SetInt(new(big.Int).Mul(gasPrice, new(big.Int).SetUint64(gas))), new(big.Float).SetInt(big.NewInt(params.Ether)))
feeFloat, _ := feeEth.Float64()
if feeFloat > cap {
return fmt.Errorf("tx fee (%.2f ether) exceeds the configured cap (%.2f ether)", feeFloat, cap)
Expand Down
12 changes: 4 additions & 8 deletions apis/atlasapi/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@ package atlasapi

import (
"fmt"
//"github.com/ethereum/go-ethereum/common"
//"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/trie"

"testing"

"github.com/ethereum/go-ethereum/trie"
"github.com/mapprotocol/atlas/core/types"
)



func Test01(t *testing.T) {
EmptyRootHash0 := types.DeriveSha(types.Transactions{},trie.NewStackTrie(nil))
EmptyRootHash0 := types.DeriveSha(types.Transactions{}, trie.NewStackTrie(nil))
fmt.Println(EmptyRootHash0)
}


6 changes: 3 additions & 3 deletions atlas/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ package atlas
import (
"context"
"errors"
"github.com/mapprotocol/atlas/core/chain"
"math/big"
"time"

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

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

"github.com/mapprotocol/atlas/accounts"
Expand Down Expand Up @@ -332,7 +332,7 @@ func (b *EthAPIBackend) RPCTxFeeCap() float64 {

func (b *EthAPIBackend) BloomStatus() (uint64, uint64) {
sections, _, _ := b.eth.bloomIndexer.Sections()
return ethparams.BloomBitsBlocks, sections
return params.BloomBitsBlocks, sections
}

func (b *EthAPIBackend) ServiceFilter(ctx context.Context, session *bloombits.MatcherSession) {
Expand Down
5 changes: 2 additions & 3 deletions atlas/catalyst/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
ethparams "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/trie"

Expand Down Expand Up @@ -162,8 +161,8 @@ func (api *consensusAPI) AssembleBlock(params assembleBlockParams) (*executableD
transactions []*types.Transaction
)
for {
if env.gasPool.Gas() < ethparams.TxGas {
log.Trace("Not enough gas for further transactions", "have", env.gasPool, "want", ethparams.TxGas)
if env.gasPool.Gas() < atlasparams.TxGas {
log.Trace("Not enough gas for further transactions", "have", env.gasPool, "want", atlasparams.TxGas)
break
}
tx := txHeap.Peek()
Expand Down
5 changes: 2 additions & 3 deletions atlas/downloader/testchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (

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

"github.com/mapprotocol/atlas/consensus/consensustest"
atlaschain "github.com/mapprotocol/atlas/core/chain"
Expand All @@ -37,7 +36,7 @@ var (
testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
testAddress = crypto.PubkeyToAddress(testKey.PublicKey)
testDB = rawdb.NewMemoryDatabase()
testGenesis = atlaschain.GenesisBlockForTesting(testDB, testAddress, new(big.Int).Mul(big.NewInt(500000), big.NewInt(ethparams.Ether)))
testGenesis = atlaschain.GenesisBlockForTesting(testDB, testAddress, new(big.Int).Mul(big.NewInt(500000), big.NewInt(params.Ether)))
)

// The common prefix of all test chains:
Expand Down Expand Up @@ -130,7 +129,7 @@ func (tc *testChain) generate(n int, seed byte, parent *types.Block, heavy bool)
if parent == tc.genesis && i%22 == 0 {
signer := types.MakeSigner(params.TestChainConfig, block.Number())
tx, err := types.SignTx(types.NewTransaction(block.TxNonce(testAddress), common.Address{seed},
big.NewInt(10), ethparams.TxGas, big.NewInt(100000000000), nil), signer, testKey)
big.NewInt(10), params.TxGas, big.NewInt(100000000000), nil), signer, testKey)
if err != nil {
panic(err)
}
Expand Down
5 changes: 2 additions & 3 deletions atlas/fetcher/block_fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (

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

"github.com/mapprotocol/atlas/consensus/consensustest"
"github.com/mapprotocol/atlas/core/chain"
Expand All @@ -41,7 +40,7 @@ var (
testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
testAddress = crypto.PubkeyToAddress(testKey.PublicKey)
genesis = chain.GenesisBlockForTesting(testdb, testAddress, big.NewInt(1000000000))
unknownBlock = types.NewBlock(&types.Header{GasLimit: ethparams.GenesisGasLimit}, nil, nil, &types.Randomness{})
unknownBlock = types.NewBlock(&types.Header{GasLimit: params.GenesisGasLimit}, nil, nil, &types.Randomness{})
)

// makeChain creates a chain of n blocks starting at and including parent.
Expand All @@ -55,7 +54,7 @@ func makeChain(n int, seed byte, parent *types.Block) ([]common.Hash, map[common
// If the block number is multiple of 3, send a bonus transaction to the miner
if parent == genesis && i%3 == 0 {
signer := types.MakeSigner(params.TestChainConfig, block.Number())
tx, err := types.SignTx(types.NewTransaction(block.TxNonce(testAddress), common.Address{seed}, big.NewInt(1000), ethparams.TxGas, nil, nil), signer, testKey)
tx, err := types.SignTx(types.NewTransaction(block.TxNonce(testAddress), common.Address{seed}, big.NewInt(1000), params.TxGas, nil, nil), signer, testKey)
if err != nil {
panic(err)
}
Expand Down
5 changes: 2 additions & 3 deletions atlas/filters/filter_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event"
ethparams "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc"

"github.com/mapprotocol/atlas/consensus/consensustest"
Expand Down Expand Up @@ -131,7 +130,7 @@ func (b *testBackend) SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subsc
}

func (b *testBackend) BloomStatus() (uint64, uint64) {
return ethparams.BloomBitsBlocks, b.sections
return params.BloomBitsBlocks, b.sections
}

func (b *testBackend) ServiceFilter(ctx context.Context, session *bloombits.MatcherSession) {
Expand All @@ -151,7 +150,7 @@ func (b *testBackend) ServiceFilter(ctx context.Context, session *bloombits.Matc
task.Bitsets = make([][]byte, len(task.Sections))
for i, section := range task.Sections {
if rand.Int()%4 != 0 { // Handle occasional missing deliveries
head := rawdb.ReadCanonicalHash(b.db, (section+1)*ethparams.BloomBitsBlocks-1)
head := rawdb.ReadCanonicalHash(b.db, (section+1)*params.BloomBitsBlocks-1)
task.Bitsets[i], _ = rawdb.ReadBloomBits(b.db, task.Bit, section, head)
}
}
Expand Down
7 changes: 3 additions & 4 deletions atlas/gasprice/gasprice.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log"
ethparams "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc"
lru "github.com/hashicorp/golang-lru"

Expand All @@ -37,9 +36,9 @@ import (
const sampleNumber = 3 // Number of transactions sampled in a block

var (
DefaultMaxPrice = big.NewInt(5000 * ethparams.GWei)
DefaultMinPrice = big.NewInt(ethparams.GWei)
DefaultIgnorePrice = big.NewInt(2 * ethparams.Wei)
DefaultMaxPrice = big.NewInt(5000 * params.GWei)
DefaultMinPrice = big.NewInt(params.GWei)
DefaultIgnorePrice = big.NewInt(2 * params.Wei)
)

type Config struct {
Expand Down
19 changes: 9 additions & 10 deletions atlas/gasprice/gasprice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/event"
ethparams "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc"

"github.com/mapprotocol/atlas/consensus/consensustest"
Expand Down Expand Up @@ -128,16 +127,16 @@ func newTestBackend(t *testing.T, londonBlock *big.Int, pending bool) *testBacke
Nonce: b.TxNonce(addr),
To: &common.Address{},
Gas: 30000,
GasFeeCap: big.NewInt(100 * ethparams.GWei),
GasTipCap: big.NewInt(int64(i+1) * ethparams.GWei),
GasFeeCap: big.NewInt(100 * params.GWei),
GasTipCap: big.NewInt(int64(i+1) * params.GWei),
Data: []byte{},
}
} else {
txdata = &types.LegacyTx{
Nonce: b.TxNonce(addr),
To: &common.Address{},
Gas: 21000,
GasPrice: big.NewInt(int64(i+1) * ethparams.GWei),
GasPrice: big.NewInt(int64(i+1) * params.GWei),
Value: big.NewInt(100),
Data: []byte{},
}
Expand Down Expand Up @@ -167,17 +166,17 @@ func TestSuggestTipCap(t *testing.T) {
config := Config{
Blocks: 3,
Percentile: 60,
Default: big.NewInt(ethparams.GWei),
Default: big.NewInt(params.GWei),
}
var cases = []struct {
fork *big.Int // London fork number
expect *big.Int // Expected gasprice suggestion
}{
{nil, big.NewInt(ethparams.GWei * int64(30))},
{big.NewInt(0), big.NewInt(ethparams.GWei * int64(30))}, // Fork point in genesis
{big.NewInt(1), big.NewInt(ethparams.GWei * int64(30))}, // Fork point in first block
{big.NewInt(32), big.NewInt(ethparams.GWei * int64(30))}, // Fork point in last block
{big.NewInt(33), big.NewInt(ethparams.GWei * int64(30))}, // Fork point in the future
{nil, big.NewInt(params.GWei * int64(30))},
{big.NewInt(0), big.NewInt(params.GWei * int64(30))}, // Fork point in genesis
{big.NewInt(1), big.NewInt(params.GWei * int64(30))}, // Fork point in first block
{big.NewInt(32), big.NewInt(params.GWei * int64(30))}, // Fork point in last block
{big.NewInt(33), big.NewInt(params.GWei * int64(30))}, // Fork point in the future
}
for _, c := range cases {
backend := newTestBackend(t, c.fork, false)
Expand Down
1 change: 0 additions & 1 deletion chains/chainsdb/chain_makers.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ package chainsdb
// "github.com/ethereum/go-ethereum/core/state"
// "github.com/ethereum/go-ethereum/core/types"
// "github.com/ethereum/go-ethereum/ethdb"
// "github.com/ethereum/go-ethereum/params"
//)
//
//// BlockGen creates blocks for testing.
Expand Down
1 change: 0 additions & 1 deletion chains/ethereum/header_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package ethereum
// "github.com/ethereum/go-ethereum/core/rawdb"
// ethtypes "github.com/ethereum/go-ethereum/core/types"
// "github.com/ethereum/go-ethereum/log"
// ethparams "github.com/ethereum/go-ethereum/params"
// "github.com/ethereum/go-ethereum/rlp"
//
// "github.com/mapprotocol/atlas/chains"
Expand Down
39 changes: 15 additions & 24 deletions chains/ethereum/make_chain_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
package ethereum

import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/params"
)

//var (
// testdb = rawdb.NewMemoryDatabase()
// testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
Expand Down Expand Up @@ -64,19 +55,19 @@ import (
//}

// makeHeaderChain creates a deterministic chain of headers rooted at parent.
func makeHeaderChain(parent *types.Header, n int, engine consensus.Engine, db ethdb.Database, seed int) []*types.Header {
blocks := makeBlockChain(types.NewBlockWithHeader(parent), n, engine, db, seed)
headers := make([]*types.Header, len(blocks))
for i, block := range blocks {
headers[i] = block.Header()
}
return headers
}
// func makeHeaderChain(parent *types.Header, n int, engine consensus.Engine, db ethdb.Database, seed int) []*types.Header {
// blocks := makeBlockChain(types.NewBlockWithHeader(parent), n, engine, db, seed)
// headers := make([]*types.Header, len(blocks))
// for i, block := range blocks {
// headers[i] = block.Header()
// }
// return headers
// }

// makeBlockChain creates a deterministic chain of blocks rooted at parent.
func makeBlockChain(parent *types.Block, n int, engine consensus.Engine, db ethdb.Database, seed int) []*types.Block {
blocks, _ := core.GenerateChain(params.TestChainConfig, parent, engine, db, n, func(i int, b *core.BlockGen) {
b.SetCoinbase(common.Address{0: byte(seed), 19: byte(i)})
})
return blocks
}
// // makeBlockChain creates a deterministic chain of blocks rooted at parent.
// func makeBlockChain(parent *types.Block, n int, engine consensus.Engine, db ethdb.Database, seed int) []*types.Block {
// blocks, _ := core.GenerateChain(params.TestChainConfig, parent, engine, db, n, func(i int, b *core.BlockGen) {
// b.SetCoinbase(common.Address{0: byte(seed), 19: byte(i)})
// })
// return blocks
// }
20 changes: 10 additions & 10 deletions chains/ethereum/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/log"
ethparams "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
"github.com/mapprotocol/atlas/params"

"github.com/mapprotocol/atlas/chains"
"github.com/mapprotocol/atlas/consensus/misc"
Expand Down Expand Up @@ -159,8 +159,8 @@ func (v *Validate) verifyHeaderWorker(hs *HeaderStore, headers []*Header, index

func (v *Validate) verifyHeader(header, parent *Header, uncle bool, unixNow int64, chainType chains.ChainType) error {
// Ensure that the header's extra-data section is of a reasonable size
if uint64(len(header.Extra)) > ethparams.MaximumExtraDataSize {
return fmt.Errorf("extra-data too long: %d > %d", len(header.Extra), ethparams.MaximumExtraDataSize)
if uint64(len(header.Extra)) > params.MaximumExtraDataSize {
return fmt.Errorf("extra-data too long: %d > %d", len(header.Extra), params.MaximumExtraDataSize)
}
// Verify the header's timestamp
if !uncle {
Expand Down Expand Up @@ -189,7 +189,7 @@ func (v *Validate) verifyHeader(header, parent *Header, uncle bool, unixNow int6

// Verify the block's gas usage and (if applicable) verify the base fee.
lb, _ := chains.ChainType2LondonBlock(chainType)
cfg := &ethparams.ChainConfig{LondonBlock: lb}
cfg := &params.ChainConfig{LondonBlock: lb}
if !cfg.IsLondon(header.Number) {
// Verify BaseFee not present before EIP-1559 fork.
if header.BaseFee != nil {
Expand All @@ -213,11 +213,11 @@ func (v *Validate) verifyHeader(header, parent *Header, uncle bool, unixNow int6
return nil
}

func VerifyEip1559Header(config *ethparams.ChainConfig, parent, header *Header) error {
func VerifyEip1559Header(config *params.ChainConfig, parent, header *Header) error {
// Verify that the gas limit remains within allowed bounds
parentGasLimit := parent.GasLimit
if !config.IsLondon(parent.Number) {
parentGasLimit = parent.GasLimit * ethparams.ElasticityMultiplier
parentGasLimit = parent.GasLimit * params.ElasticityMultiplier
}
if err := misc.VerifyGaslimit(parentGasLimit, header.GasLimit); err != nil {
return err
Expand All @@ -236,16 +236,16 @@ func VerifyEip1559Header(config *ethparams.ChainConfig, parent, header *Header)
}

// CalcBaseFee calculates the basefee of the header.
func CalcBaseFee(config *ethparams.ChainConfig, parent *Header) *big.Int {
func CalcBaseFee(config *params.ChainConfig, parent *Header) *big.Int {
// If the current block is the first EIP-1559 block, return the InitialBaseFee.
if !config.IsLondon(parent.Number) {
return new(big.Int).SetUint64(ethparams.InitialBaseFee)
return new(big.Int).SetUint64(params.InitialBaseFee)
}

var (
parentGasTarget = parent.GasLimit / ethparams.ElasticityMultiplier
parentGasTarget = parent.GasLimit / params.ElasticityMultiplier
parentGasTargetBig = new(big.Int).SetUint64(parentGasTarget)
baseFeeChangeDenominator = new(big.Int).SetUint64(ethparams.BaseFeeChangeDenominator)
baseFeeChangeDenominator = new(big.Int).SetUint64(params.BaseFeeChangeDenominator)
)
// If the parent gasUsed is the same as the target, the baseFee remains unchanged.
if parent.GasUsed == parentGasTarget {
Expand Down

0 comments on commit 14bfb03

Please sign in to comment.