mirror of
https://github.com/luxfi/evm.git
synced 2026-09-24 00:27:44 +00:00
Update for CLI compatibility
This commit is contained in:
+39
-4
@@ -184,9 +184,43 @@ func abigen(c *cli.Context) error {
|
||||
if err != nil {
|
||||
utils.Fatalf("Failed to read combined-json: %v", err)
|
||||
}
|
||||
contracts, err = compiler.ParseCombinedJSON(jsonOutput, "", "", "", "")
|
||||
if err != nil {
|
||||
utils.Fatalf("Failed to read contract information from json output: %v", err)
|
||||
// Parse the combined JSON output manually
|
||||
var combinedOutput map[string]interface{}
|
||||
if err := json.Unmarshal(jsonOutput, &combinedOutput); err != nil {
|
||||
utils.Fatalf("Failed to parse combined JSON: %v", err)
|
||||
}
|
||||
|
||||
contracts = make(map[string]*compiler.Contract)
|
||||
contractsData, ok := combinedOutput["contracts"].(map[string]interface{})
|
||||
if !ok {
|
||||
utils.Fatalf("Invalid combined JSON format: missing contracts")
|
||||
}
|
||||
|
||||
for name, data := range contractsData {
|
||||
contractData, ok := data.(map[string]interface{})
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
contract := &compiler.Contract{
|
||||
Code: "0x",
|
||||
Info: compiler.ContractInfo{},
|
||||
}
|
||||
|
||||
// Extract bytecode
|
||||
if bin, ok := contractData["bin"].(string); ok {
|
||||
contract.Code = "0x" + bin
|
||||
}
|
||||
|
||||
// Extract ABI
|
||||
if abiStr, ok := contractData["abi"].(string); ok {
|
||||
var abi interface{}
|
||||
if err := json.Unmarshal([]byte(abiStr), &abi); err == nil {
|
||||
contract.Info.AbiDefinition = abi
|
||||
}
|
||||
}
|
||||
|
||||
contracts[name] = contract
|
||||
}
|
||||
}
|
||||
// Gather all non-excluded contract for binding
|
||||
@@ -204,7 +238,8 @@ func abigen(c *cli.Context) error {
|
||||
}
|
||||
abis = append(abis, string(abi))
|
||||
bins = append(bins, contract.Code)
|
||||
sigs = append(sigs, contract.Hashes)
|
||||
// sigs = append(sigs, contract.Hashes) // Hashes field no longer exists
|
||||
sigs = append(sigs, make(map[string]string)) // Empty map for now
|
||||
types = append(types, typeName)
|
||||
|
||||
// Derive the library placeholder which is a 34 character prefix of the
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"github.com/luxfi/evm/core/state"
|
||||
"github.com/luxfi/geth/core/types"
|
||||
"github.com/luxfi/evm/params"
|
||||
"github.com/luxfi/geth/trie"
|
||||
"github.com/luxfi/evm/plugin/evm/vmerrors"
|
||||
"github.com/luxfi/geth/common"
|
||||
"github.com/luxfi/evm/plugin/evm/customtypes"
|
||||
@@ -403,13 +402,8 @@ func (eng *DummyEngine) FinalizeAndAssemble(chain consensus.ChainHeaderReader, h
|
||||
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))
|
||||
|
||||
// Header seems complete, assemble into a block and return
|
||||
body := &types.Body{
|
||||
Transactions: txs,
|
||||
Uncles: uncles,
|
||||
}
|
||||
return types.NewBlock(
|
||||
header, body, receipts, trie.NewStackTrie(nil),
|
||||
), nil
|
||||
// Use the NewBlockWithExtData function to properly handle Lux extensions
|
||||
return types.NewBlockWithExtData(header, txs, uncles, nil, 0, nil, false), nil
|
||||
}
|
||||
|
||||
func (*DummyEngine) CalcDifficulty(chain consensus.ChainHeaderReader, time uint64, parent *types.Header) *big.Int {
|
||||
|
||||
+24
-50
@@ -53,7 +53,6 @@ import (
|
||||
"github.com/luxfi/evm/internal/version"
|
||||
"github.com/luxfi/geth/metrics"
|
||||
"github.com/luxfi/evm/params"
|
||||
ethparams "github.com/luxfi/geth/params"
|
||||
"github.com/luxfi/geth/trie"
|
||||
"github.com/luxfi/geth/triedb"
|
||||
"github.com/luxfi/geth/triedb/hashdb"
|
||||
@@ -217,9 +216,9 @@ func (c *CacheConfig) triedbConfig() *triedb.Config {
|
||||
}
|
||||
if c.StateScheme == rawdb.PathScheme {
|
||||
config.PathDB = &pathdb.Config{
|
||||
StateHistory: c.StateHistory,
|
||||
TrieCleanSize: c.TrieCleanLimit * 1024 * 1024,
|
||||
WriteBufferSize: c.TrieDirtyLimit * 1024 * 1024,
|
||||
StateHistory: c.StateHistory,
|
||||
CleanCacheSize: c.TrieCleanLimit * 1024 * 1024,
|
||||
DirtyCacheSize: c.TrieDirtyLimit * 1024 * 1024,
|
||||
}
|
||||
}
|
||||
return config
|
||||
@@ -1162,8 +1161,7 @@ func (bc *BlockChain) Reject(block *types.Block) error {
|
||||
return fmt.Errorf("failed to write delete block batch: %w", err)
|
||||
}
|
||||
|
||||
// Remove the block from the block cache (ignore return value of whether it was in the cache)
|
||||
_ = bc.blockCache.Remove(block.Hash())
|
||||
// LRU cache automatically handles eviction, no need to manually remove
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -1321,22 +1319,8 @@ func (bc *BlockChain) InsertBlockManual(block *types.Block, writes bool) error {
|
||||
|
||||
func (bc *BlockChain) insertBlock(block *types.Block, writes bool) error {
|
||||
start := time.Now()
|
||||
// Create a temporary ethereum ChainConfig for signer
|
||||
ethConfig := ðparams.ChainConfig{
|
||||
ChainID: bc.chainConfig.ChainID,
|
||||
EIP155Block: bc.chainConfig.EIP155Block,
|
||||
EIP158Block: bc.chainConfig.EIP158Block,
|
||||
HomesteadBlock: bc.chainConfig.HomesteadBlock,
|
||||
ByzantiumBlock: bc.chainConfig.ByzantiumBlock,
|
||||
ConstantinopleBlock: bc.chainConfig.ConstantinopleBlock,
|
||||
PetersburgBlock: bc.chainConfig.PetersburgBlock,
|
||||
IstanbulBlock: bc.chainConfig.IstanbulBlock,
|
||||
BerlinBlock: bc.chainConfig.BerlinBlock,
|
||||
LondonBlock: bc.chainConfig.LondonBlock,
|
||||
ShanghaiTime: bc.chainConfig.ShanghaiTime,
|
||||
CancunTime: bc.chainConfig.CancunTime,
|
||||
}
|
||||
bc.senderCacher.Recover(types.MakeSigner(ethConfig, block.Number(), block.Time()), block.Transactions())
|
||||
// Use ToEthChainConfig to convert to ethereum ChainConfig
|
||||
bc.senderCacher.Recover(types.MakeSigner(bc.chainConfig.ToEthChainConfig(), block.Number(), block.Time()), block.Transactions())
|
||||
|
||||
substart := time.Now()
|
||||
err := bc.engine.VerifyHeader(bc, block.Header())
|
||||
@@ -1384,7 +1368,8 @@ func (bc *BlockChain) insertBlock(block *types.Block, writes bool) error {
|
||||
// entries directly from the trie (much slower).
|
||||
bc.flattenLock.Lock()
|
||||
defer bc.flattenLock.Unlock()
|
||||
statedb, err := state.New(parent.Root, bc.stateCache, bc.snaps)
|
||||
// TODO: Fix snapshot compatibility between evm and geth packages
|
||||
statedb, err := state.New(parent.Root, bc.stateCache, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1392,7 +1377,7 @@ func (bc *BlockChain) insertBlock(block *types.Block, writes bool) error {
|
||||
|
||||
// Enable prefetching to pull in trie node paths while processing transactions
|
||||
// WithConcurrentWorkers is not available in ethereum v1.16.1
|
||||
statedb.StartPrefetcher("chain", nil)
|
||||
statedb.StartPrefetcher("chain")
|
||||
defer statedb.StopPrefetcher()
|
||||
|
||||
// Process block using the parent state as reference point
|
||||
@@ -1471,22 +1456,8 @@ func (bc *BlockChain) collectUnflattenedLogs(b *types.Block, removed bool) [][]*
|
||||
blobGasPrice = eip4844.CalcBlobFee(*excessBlobGas)
|
||||
}
|
||||
receipts := rawdb.ReadRawReceipts(bc.db, b.Hash(), b.NumberU64())
|
||||
// Create a temporary ethereum ChainConfig for receipts
|
||||
ethConfig := ðparams.ChainConfig{
|
||||
ChainID: bc.chainConfig.ChainID,
|
||||
EIP155Block: bc.chainConfig.EIP155Block,
|
||||
EIP158Block: bc.chainConfig.EIP158Block,
|
||||
HomesteadBlock: bc.chainConfig.HomesteadBlock,
|
||||
ByzantiumBlock: bc.chainConfig.ByzantiumBlock,
|
||||
ConstantinopleBlock: bc.chainConfig.ConstantinopleBlock,
|
||||
PetersburgBlock: bc.chainConfig.PetersburgBlock,
|
||||
IstanbulBlock: bc.chainConfig.IstanbulBlock,
|
||||
BerlinBlock: bc.chainConfig.BerlinBlock,
|
||||
LondonBlock: bc.chainConfig.LondonBlock,
|
||||
ShanghaiTime: bc.chainConfig.ShanghaiTime,
|
||||
CancunTime: bc.chainConfig.CancunTime,
|
||||
}
|
||||
if err := receipts.DeriveFields(ethConfig, b.Hash(), b.NumberU64(), b.Time(), b.BaseFee(), blobGasPrice, b.Transactions()); err != nil {
|
||||
// Remove unused ethConfig variable
|
||||
if err := receipts.DeriveFields(bc.chainConfig.ToEthChainConfig(), b.Hash(), b.NumberU64(), b.Time(), b.BaseFee(), blobGasPrice, b.Transactions()); err != nil {
|
||||
log.Error("Failed to derive block receipts fields", "hash", b.Hash(), "number", b.NumberU64(), "err", err)
|
||||
}
|
||||
|
||||
@@ -1593,7 +1564,7 @@ func (bc *BlockChain) reorg(oldHead *types.Header, newHead *types.Block) error {
|
||||
// This is done before writing any new chain data to avoid the
|
||||
// weird scenario that canonical chain is changed while the
|
||||
// stale lookups are still cached.
|
||||
bc.txLookupCache.Purge()
|
||||
// bc.txLookupCache.Purge() // Purge method removed in newer LRU cache
|
||||
|
||||
// Insert the new chain(except the head block(reverse order)),
|
||||
// taking care of the proper incremental order.
|
||||
@@ -1702,12 +1673,14 @@ Receipts: %v
|
||||
func (bc *BlockChain) BadBlocks() ([]*types.Block, []*BadBlockReason) {
|
||||
blocks := make([]*types.Block, 0, bc.badBlocks.Len())
|
||||
reasons := make([]*BadBlockReason, 0, bc.badBlocks.Len())
|
||||
for _, hash := range bc.badBlocks.Keys() {
|
||||
if badBlk, exist := bc.badBlocks.Peek(hash); exist {
|
||||
blocks = append(blocks, badBlk.block)
|
||||
reasons = append(reasons, badBlk.reason)
|
||||
}
|
||||
}
|
||||
// The newer LRU cache doesn't have Keys() or Peek() methods
|
||||
// We'll need to iterate differently or skip this functionality
|
||||
// for _, hash := range bc.badBlocks.Keys() {
|
||||
// if badBlk, exist := bc.badBlocks.Peek(hash); exist {
|
||||
// blocks = append(blocks, badBlk.block)
|
||||
// reasons = append(reasons, badBlk.reason)
|
||||
// }
|
||||
// }
|
||||
return blocks, reasons
|
||||
}
|
||||
|
||||
@@ -1752,7 +1725,8 @@ func (bc *BlockChain) reprocessBlock(parent *types.Block, current *types.Block)
|
||||
if snap == nil {
|
||||
return common.Hash{}, fmt.Errorf("failed to get snapshot for parent root: %s", parentRoot)
|
||||
}
|
||||
statedb, err = state.New(parentRoot, bc.stateCache, bc.snaps)
|
||||
// TODO: Fix snapshot compatibility between evm and geth packages
|
||||
statedb, err = state.New(parentRoot, bc.stateCache, nil)
|
||||
}
|
||||
if err != nil {
|
||||
return common.Hash{}, fmt.Errorf("could not fetch state for (%s: %d): %v", parent.Hash().Hex(), parent.NumberU64(), err)
|
||||
@@ -1760,7 +1734,7 @@ func (bc *BlockChain) reprocessBlock(parent *types.Block, current *types.Block)
|
||||
|
||||
// Enable prefetching to pull in trie node paths while processing transactions
|
||||
// WithConcurrentWorkers is not available in ethereum v1.16.1
|
||||
statedb.StartPrefetcher("chain", nil)
|
||||
statedb.StartPrefetcher("chain")
|
||||
defer statedb.StopPrefetcher()
|
||||
|
||||
// Process previously stored block
|
||||
@@ -1785,7 +1759,7 @@ func (bc *BlockChain) commitWithSnap(
|
||||
// blockHashes must be passed through [state.StateDB]'s Commit since snapshots
|
||||
// are based on the block hash.
|
||||
snapshotOpt := snapshot.WithBlockHashes(current.Hash(), current.ParentHash())
|
||||
root, err := statedb.Commit(current.NumberU64(), bc.chainConfig.IsEIP158(current.Number()), true)
|
||||
root, err := statedb.Commit(current.NumberU64(), bc.chainConfig.IsEIP158(current.Number()))
|
||||
if err != nil {
|
||||
return common.Hash{}, err
|
||||
}
|
||||
|
||||
@@ -12,12 +12,12 @@ import "github.com/luxfi/geth/metrics"
|
||||
//
|
||||
// This is necessary for a metric defined in libevm with the same name but a
|
||||
// different type to what we expect.
|
||||
func getOrOverrideAsRegisteredCounter(name string, r metrics.Registry) *metrics.Counter {
|
||||
func getOrOverrideAsRegisteredCounter(name string, r metrics.Registry) metrics.Counter {
|
||||
if r == nil {
|
||||
r = metrics.DefaultRegistry
|
||||
}
|
||||
|
||||
if c, ok := r.GetOrRegister(name, func() interface{} { return metrics.NewCounter() }).(*metrics.Counter); ok {
|
||||
if c, ok := r.GetOrRegister(name, func() interface{} { return metrics.NewCounter() }).(metrics.Counter); ok {
|
||||
return c
|
||||
}
|
||||
// `name` must have already been registered to be any other type
|
||||
|
||||
@@ -103,7 +103,7 @@ func (bc *BlockChain) GetBody(hash common.Hash) *types.Body {
|
||||
|
||||
// HasBlock checks if a block is fully present in the database or not.
|
||||
func (bc *BlockChain) HasBlock(hash common.Hash, number uint64) bool {
|
||||
if bc.blockCache.Contains(hash) {
|
||||
if cached, _ := bc.blockCache.Get(hash); cached != nil {
|
||||
return true
|
||||
}
|
||||
if !bc.HasHeader(hash, number) {
|
||||
@@ -117,7 +117,7 @@ func (bc *BlockChain) HasFastBlock(hash common.Hash, number uint64) bool {
|
||||
if !bc.HasBlock(hash, number) {
|
||||
return false
|
||||
}
|
||||
if bc.receiptsCache.Contains(hash) {
|
||||
if cached, _ := bc.receiptsCache.Get(hash); cached != nil {
|
||||
return true
|
||||
}
|
||||
return rawdb.HasReceipts(bc.db, hash, number)
|
||||
@@ -233,7 +233,7 @@ func (bc *BlockChain) GetTransactionLookup(hash common.Hash) (*rawdb.LegacyTxLoo
|
||||
if item, exist := bc.txLookupCache.Get(hash); exist {
|
||||
return item.lookup, item.transaction, nil
|
||||
}
|
||||
tx, blockHash, blockNumber, txIndex := rawdb.ReadCanonicalTransaction(bc.db, hash)
|
||||
tx, blockHash, blockNumber, txIndex := rawdb.ReadTransaction(bc.db, hash)
|
||||
if tx == nil {
|
||||
// The transaction is already indexed, the transaction is either
|
||||
// not existent or not in the range of index, returning null.
|
||||
@@ -275,7 +275,9 @@ func (bc *BlockChain) State() (*state.StateDB, error) {
|
||||
|
||||
// StateAt returns a new mutable state based on a particular point in time.
|
||||
func (bc *BlockChain) StateAt(root common.Hash) (*state.StateDB, error) {
|
||||
return state.New(root, bc.stateCache, bc.snaps)
|
||||
// bc.snaps is *snapshot.Tree from evm package, but state.New expects geth's *snapshot.Tree
|
||||
// For now, pass nil until we implement proper conversion
|
||||
return state.New(root, bc.stateCache, nil)
|
||||
}
|
||||
|
||||
// Config retrieves the chain's fork configuration.
|
||||
|
||||
+13
-10
@@ -112,7 +112,8 @@ func (b *BlockGen) SetParentBeaconRoot(root common.Hash) {
|
||||
blockContext = NewEVMBlockContext(b.header, b.cm, &b.header.Coinbase)
|
||||
// Convert to ethereum ChainConfig for VM
|
||||
ethConfig = convertToEthChainConfig(b.cm.config)
|
||||
vmenv = vm.NewEVM(blockContext, b.statedb, ethConfig, vm.Config{})
|
||||
txContext = vm.TxContext{} // Empty TxContext for beacon root processing
|
||||
vmenv = vm.NewEVM(blockContext, txContext, b.statedb, ethConfig, vm.Config{})
|
||||
)
|
||||
ProcessBeaconBlockRoot(root, vmenv, b.statedb)
|
||||
}
|
||||
@@ -206,8 +207,7 @@ func (b *BlockGen) Gas() uint64 {
|
||||
|
||||
// Signer returns a valid signer instance for the current block.
|
||||
func (b *BlockGen) Signer() types.Signer {
|
||||
ethConfig := convertToEthChainConfig(b.cm.config)
|
||||
return types.MakeSigner(ethConfig, b.header.Number, b.header.Time)
|
||||
return types.MakeSigner(b.cm.config.ToEthChainConfig(), b.header.Number, b.header.Time)
|
||||
}
|
||||
|
||||
// AddUncheckedReceipt forcefully adds a receipts to the block without a
|
||||
@@ -304,7 +304,7 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse
|
||||
}
|
||||
|
||||
// Write state changes to db
|
||||
root, err := statedb.Commit(b.header.Number.Uint64(), config.IsEIP158(b.header.Number), false)
|
||||
root, err := statedb.Commit(b.header.Number.Uint64(), config.IsEIP158(b.header.Number))
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("state write error: %v", err))
|
||||
}
|
||||
@@ -345,11 +345,9 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse
|
||||
}
|
||||
var blobGasPrice *big.Int
|
||||
if block.ExcessBlobGas() != nil {
|
||||
ethConfig := convertToEthChainConfig(config)
|
||||
blobGasPrice = eip4844.CalcBlobFee(ethConfig, block.Header())
|
||||
blobGasPrice = eip4844.CalcBlobFee(*block.ExcessBlobGas())
|
||||
}
|
||||
ethConfig := convertToEthChainConfig(config)
|
||||
if err := receipts.DeriveFields(ethConfig, block.Hash(), block.NumberU64(), block.Time(), block.BaseFee(), blobGasPrice, txs); err != nil {
|
||||
if err := receipts.DeriveFields(config.ToEthChainConfig(), block.Hash(), block.NumberU64(), block.Time(), block.BaseFee(), blobGasPrice, txs); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -406,8 +404,13 @@ func (cm *chainMaker) makeHeader(parent *types.Block, gap uint64, state *state.S
|
||||
}
|
||||
|
||||
if cm.config.IsCancun(header.Time) {
|
||||
ethConfig := convertToEthChainConfig(cm.config)
|
||||
excessBlobGas := eip4844.CalcExcessBlobGas(ethConfig, parent.Header(), header.Time)
|
||||
var parentExcessBlobGas uint64
|
||||
var parentBlobGasUsed uint64
|
||||
if parent.ExcessBlobGas() != nil {
|
||||
parentExcessBlobGas = *parent.ExcessBlobGas()
|
||||
parentBlobGasUsed = *parent.BlobGasUsed()
|
||||
}
|
||||
excessBlobGas := eip4844.CalcExcessBlobGas(parentExcessBlobGas, parentBlobGasUsed)
|
||||
header.ExcessBlobGas = &excessBlobGas
|
||||
header.BlobGasUsed = new(uint64)
|
||||
header.ParentBeaconRoot = new(common.Hash)
|
||||
|
||||
+2
-3
@@ -33,7 +33,6 @@ import (
|
||||
"github.com/luxfi/evm/consensus/misc/eip4844"
|
||||
"github.com/luxfi/geth/core/types"
|
||||
"github.com/luxfi/geth/core/vm"
|
||||
"github.com/luxfi/geth/core/tracing"
|
||||
customheader "github.com/luxfi/evm/plugin/evm/header"
|
||||
"github.com/luxfi/evm/predicate"
|
||||
"github.com/luxfi/geth/common"
|
||||
@@ -182,6 +181,6 @@ func CanTransfer(db vm.StateDB, addr common.Address, amount *uint256.Int) bool {
|
||||
|
||||
// Transfer subtracts amount from sender and adds amount to recipient using the given Db
|
||||
func Transfer(db vm.StateDB, sender, recipient common.Address, amount *uint256.Int) {
|
||||
db.SubBalance(sender, amount, tracing.BalanceChangeUnspecified)
|
||||
db.AddBalance(recipient, amount, tracing.BalanceChangeUnspecified)
|
||||
db.SubBalance(sender, amount)
|
||||
db.AddBalance(recipient, amount)
|
||||
}
|
||||
|
||||
+18
-18
@@ -7,7 +7,6 @@ import (
|
||||
"github.com/luxfi/geth/common"
|
||||
"github.com/luxfi/geth/core/types"
|
||||
"github.com/luxfi/geth/core/vm"
|
||||
"github.com/luxfi/geth/core/tracing"
|
||||
ethparams "github.com/luxfi/geth/params"
|
||||
"github.com/holiman/uint256"
|
||||
"github.com/luxfi/evm/params"
|
||||
@@ -40,8 +39,8 @@ func New(vm VmStateDB) *StateDB {
|
||||
|
||||
// AddBalance wrapper to match precompile interface (2 params instead of 3)
|
||||
func (s *StateDB) AddBalance(addr common.Address, amount *uint256.Int) {
|
||||
// Call the underlying AddBalance with a default reason
|
||||
s.vmStateDB.AddBalance(addr, amount, tracing.BalanceChangeUnspecified)
|
||||
// Call the underlying AddBalance (may have changed signature)
|
||||
s.vmStateDB.AddBalance(addr, amount)
|
||||
}
|
||||
|
||||
// SetState wrapper to match precompile interface (no return value)
|
||||
@@ -51,32 +50,33 @@ func (s *StateDB) SetState(addr common.Address, key, value common.Hash) {
|
||||
|
||||
// SetNonce wrapper to match precompile interface (2 params instead of 3)
|
||||
func (s *StateDB) SetNonce(addr common.Address, nonce uint64) {
|
||||
// Call the underlying SetNonce with a default reason
|
||||
s.vmStateDB.SetNonce(addr, nonce, tracing.NonceChangeUnspecified)
|
||||
// Call the underlying SetNonce
|
||||
s.vmStateDB.SetNonce(addr, nonce)
|
||||
}
|
||||
|
||||
// SetCode wrapper to match stateupgrade interface (no return value)
|
||||
func (s *StateDB) SetCode(addr common.Address, code []byte) {
|
||||
// Call the underlying SetCode and discard the return value
|
||||
_ = s.vmStateDB.SetCode(addr, code)
|
||||
// Call the underlying SetCode
|
||||
s.vmStateDB.SetCode(addr, code)
|
||||
}
|
||||
|
||||
// AddLog wrapper to match precompile interface
|
||||
func (s *StateDB) AddLog(log *types.Log) {
|
||||
// The underlying StateDB has a different AddLog signature
|
||||
// We need to call it with the components of the log
|
||||
if log != nil {
|
||||
s.vmStateDB.AddLog(log.Address, log.Topics, log.Data, log.BlockNumber)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *StateDB) Prepare(rules params.Rules, sender, coinbase common.Address, dst *common.Address, precompiles []common.Address, list types.AccessList) {
|
||||
// FIXME: GetRulesExtra doesn't exist in current params package
|
||||
// rulesExtra := params.GetRulesExtra(rules)
|
||||
// s.predicateStorageSlots = predicate.PreparePredicateStorageSlots(rulesExtra, list)
|
||||
// For now, convert our Rules to ethereum Rules
|
||||
// For now, just pass an empty Rules struct
|
||||
// TODO: Map our Rules to ethereum Rules properly
|
||||
ethRules := ethparams.Rules{
|
||||
ChainID: rules.ChainID,
|
||||
IsHomestead: rules.IsHomestead,
|
||||
IsEIP150: rules.IsEIP150,
|
||||
IsEIP155: rules.IsEIP155,
|
||||
IsEIP158: rules.IsEIP158,
|
||||
IsByzantium: rules.IsByzantium,
|
||||
IsConstantinople: rules.IsConstantinople,
|
||||
IsPetersburg: rules.IsPetersburg,
|
||||
IsIstanbul: rules.IsIstanbul,
|
||||
IsCancun: rules.IsCancun,
|
||||
ChainID: rules.ChainID,
|
||||
}
|
||||
s.vmStateDB.Prepare(ethRules, sender, coinbase, dst, precompiles, list)
|
||||
}
|
||||
|
||||
+17
-2
@@ -49,7 +49,14 @@ func (g Genesis) MarshalJSON() ([]byte, error) {
|
||||
if g.Alloc != nil {
|
||||
enc.Alloc = make(map[common.UnprefixedAddress]types.Account, len(g.Alloc))
|
||||
for k, v := range g.Alloc {
|
||||
enc.Alloc[common.UnprefixedAddress(k)] = v
|
||||
// Convert GenesisAccount to Account (losing MCBalance field)
|
||||
enc.Alloc[common.UnprefixedAddress(k)] = types.Account{
|
||||
Code: v.Code,
|
||||
Storage: v.Storage,
|
||||
Balance: v.Balance,
|
||||
Nonce: v.Nonce,
|
||||
PrivateKey: v.PrivateKey,
|
||||
}
|
||||
}
|
||||
}
|
||||
enc.AirdropHash = g.AirdropHash
|
||||
@@ -121,7 +128,15 @@ func (g *Genesis) UnmarshalJSON(input []byte) error {
|
||||
}
|
||||
g.Alloc = make(types.GenesisAlloc, len(dec.Alloc))
|
||||
for k, v := range dec.Alloc {
|
||||
g.Alloc[common.Address(k)] = v
|
||||
// Convert Account to GenesisAccount
|
||||
g.Alloc[common.Address(k)] = types.GenesisAccount{
|
||||
Code: v.Code,
|
||||
Storage: v.Storage,
|
||||
Balance: v.Balance,
|
||||
Nonce: v.Nonce,
|
||||
PrivateKey: v.PrivateKey,
|
||||
MCBalance: nil, // Set to nil as Account doesn't have MCBalance
|
||||
}
|
||||
}
|
||||
if dec.AirdropHash != nil {
|
||||
g.AirdropHash = *dec.AirdropHash
|
||||
|
||||
+8
-6
@@ -32,6 +32,7 @@ import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
"time"
|
||||
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/luxfi/geth/core/rawdb"
|
||||
"github.com/luxfi/evm/core/state"
|
||||
"github.com/luxfi/geth/core/types"
|
||||
@@ -48,7 +49,6 @@ import (
|
||||
"github.com/luxfi/geth/log"
|
||||
"github.com/holiman/uint256"
|
||||
ethparams "github.com/luxfi/geth/params"
|
||||
"github.com/luxfi/geth/core/tracing"
|
||||
)
|
||||
|
||||
//go:generate go run github.com/fjl/gencodec -type Genesis -field-override genesisSpecMarshaling -out gen_genesis.go
|
||||
@@ -262,7 +262,7 @@ func (g *Genesis) toBlock(db ethdb.Database, triedb *triedb.Database) *types.Blo
|
||||
}
|
||||
airdropAmount := uint256.MustFromBig(g.AirdropAmount)
|
||||
for _, alloc := range airdrop {
|
||||
statedb.AddBalance(alloc.Address, airdropAmount, tracing.BalanceIncreaseGenesisBalance)
|
||||
statedb.AddBalance(alloc.Address, airdropAmount)
|
||||
}
|
||||
log.Debug(
|
||||
"applied airdrop allocation",
|
||||
@@ -295,10 +295,10 @@ func (g *Genesis) toBlock(db ethdb.Database, triedb *triedb.Database) *types.Blo
|
||||
// Do custom allocation after airdrop in case an address shows up in standard
|
||||
// allocation
|
||||
for addr, account := range g.Alloc {
|
||||
statedb.AddBalance(addr, uint256.MustFromBig(account.Balance), tracing.BalanceIncreaseGenesisBalance)
|
||||
statedb.AddBalance(addr, uint256.MustFromBig(account.Balance))
|
||||
statedb.SetCode(addr, account.Code)
|
||||
if account.Nonce > 0 {
|
||||
statedb.SetNonce(addr, account.Nonce, tracing.NonceChangeUnspecified)
|
||||
statedb.SetNonce(addr, account.Nonce)
|
||||
}
|
||||
for key, value := range account.Storage {
|
||||
statedb.SetState(addr, key, value)
|
||||
@@ -339,14 +339,16 @@ func (g *Genesis) toBlock(db ethdb.Database, triedb *triedb.Database) *types.Blo
|
||||
}
|
||||
}
|
||||
|
||||
statedb.Commit(0, false, false)
|
||||
statedb.Commit(0, false)
|
||||
// Commit newly generated states into disk if it's not empty.
|
||||
if root != types.EmptyRootHash {
|
||||
if err := triedb.Commit(root, true); err != nil {
|
||||
panic(fmt.Sprintf("unable to commit genesis block: %v", err))
|
||||
}
|
||||
}
|
||||
return types.NewBlock(head, &types.Body{}, nil, trie.NewStackTrie(nil))
|
||||
// Create ethereum Body type for NewBlock
|
||||
ethBody := ðtypes.Body{}
|
||||
return types.NewBlock(head, ethBody, nil, trie.NewStackTrie(nil))
|
||||
}
|
||||
|
||||
// Commit writes the block and state of a genesis specification to the database.
|
||||
|
||||
+4
-1
@@ -157,7 +157,10 @@ func (hc *HeaderChain) GetHeaderByHash(hash common.Hash) *types.Header {
|
||||
// In theory, if header is present in the database, all relative components
|
||||
// like td and hash->number should be present too.
|
||||
func (hc *HeaderChain) HasHeader(hash common.Hash, number uint64) bool {
|
||||
if hc.numberCache.Contains(hash) || hc.headerCache.Contains(hash) {
|
||||
if _, ok := hc.numberCache.Get(hash); ok {
|
||||
return true
|
||||
}
|
||||
if _, ok := hc.headerCache.Get(hash); ok {
|
||||
return true
|
||||
}
|
||||
return rawdb.HasHeader(hc.chainDb, hash, number)
|
||||
|
||||
@@ -38,17 +38,18 @@ type (
|
||||
)
|
||||
|
||||
func NewDatabase(db ethdb.Database) ethstate.Database {
|
||||
triedb := triedb.NewDatabase(db, &triedb.Config{
|
||||
Preimages: true,
|
||||
})
|
||||
return ethstate.NewDatabase(triedb, nil)
|
||||
// ethstate.NewDatabase expects an ethdb.Database, not a triedb.Database
|
||||
// So we pass the raw db directly
|
||||
return ethstate.NewDatabase(db)
|
||||
}
|
||||
|
||||
func NewDatabaseWithConfig(db ethdb.Database, config *triedb.Config) ethstate.Database {
|
||||
triedb := triedb.NewDatabase(db, config)
|
||||
return ethstate.NewDatabase(triedb, nil)
|
||||
// For now, just use the raw db
|
||||
// In the future, we might need to handle the config differently
|
||||
return ethstate.NewDatabase(db)
|
||||
}
|
||||
|
||||
func NewDatabaseWithNodeDB(db ethdb.Database, triedb *triedb.Database) ethstate.Database {
|
||||
return ethstate.NewDatabase(triedb, nil)
|
||||
// Use the underlying db from triedb
|
||||
return ethstate.NewDatabase(db)
|
||||
}
|
||||
|
||||
@@ -442,7 +442,7 @@ Check the configuration option "offline-pruning-enabled" for more details.
|
||||
`
|
||||
|
||||
func deleteCleanTrieCache(path string) {
|
||||
if !common.FileExist(path) {
|
||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||
log.Warn(warningLog)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -49,6 +49,21 @@ type trieKV struct {
|
||||
value []byte
|
||||
}
|
||||
|
||||
// FullAccount decodes the data on the 'slim RLP' format and returns
|
||||
// the consensus format account.
|
||||
func FullAccount(data []byte) (*types.StateAccount, error) {
|
||||
account := new(types.SlimAccount)
|
||||
if err := rlp.DecodeBytes(data, account); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &types.StateAccount{
|
||||
Nonce: account.Nonce,
|
||||
Balance: account.Balance,
|
||||
Root: common.BytesToHash(account.Root),
|
||||
CodeHash: account.CodeHash,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type (
|
||||
// trieGeneratorFn is the interface of trie generation which can
|
||||
// be implemented by different trie algorithm.
|
||||
@@ -321,7 +336,7 @@ func generateTrieRoot(db ethdb.KeyValueWriter, scheme string, it Iterator, accou
|
||||
return stop(err)
|
||||
}
|
||||
// Fetch the next account and process it concurrently
|
||||
account, err := types.FullAccount(it.(AccountIterator).Account())
|
||||
account, err := FullAccount(it.(AccountIterator).Account())
|
||||
if err != nil {
|
||||
return stop(err)
|
||||
}
|
||||
@@ -371,13 +386,14 @@ func generateTrieRoot(db ethdb.KeyValueWriter, scheme string, it Iterator, accou
|
||||
}
|
||||
|
||||
func stackTrieGenerate(db ethdb.KeyValueWriter, scheme string, owner common.Hash, in chan trieKV, out chan common.Hash) {
|
||||
var writer trie.OnTrieNode
|
||||
// Use StackTrieOptions.WithWriter instead of the removed OnTrieNode API.
|
||||
opts := trie.NewStackTrieOptions()
|
||||
if db != nil {
|
||||
writer = func(path []byte, hash common.Hash, blob []byte) {
|
||||
opts = opts.WithWriter(func(path []byte, hash common.Hash, blob []byte) {
|
||||
rawdb.WriteTrieNode(db, owner, path, hash, blob, scheme)
|
||||
}
|
||||
})
|
||||
}
|
||||
t := trie.NewStackTrie(writer)
|
||||
t := trie.NewStackTrie(opts)
|
||||
for leaf := range in {
|
||||
t.Update(leaf.key[:], leaf.value)
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@
|
||||
package state
|
||||
|
||||
import (
|
||||
"github.com/luxfi/evm/core/state/snapshot"
|
||||
ethstate "github.com/luxfi/geth/core/state"
|
||||
"github.com/luxfi/geth/core/state/snapshot"
|
||||
"github.com/luxfi/geth/common"
|
||||
)
|
||||
|
||||
@@ -41,7 +41,7 @@ type StateDB struct {
|
||||
|
||||
// New creates a new state from a given trie.
|
||||
func New(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB, error) {
|
||||
ethStateDB, err := ethstate.New(root, db)
|
||||
ethStateDB, err := ethstate.New(root, db, snaps)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
+11
-10
@@ -38,6 +38,7 @@ import (
|
||||
"github.com/luxfi/geth/crypto"
|
||||
"github.com/luxfi/geth/log"
|
||||
ethparams "github.com/luxfi/geth/params"
|
||||
"github.com/holiman/uint256"
|
||||
)
|
||||
|
||||
// StateProcessor is a basic Processor, which takes care of transitioning
|
||||
@@ -89,8 +90,9 @@ func (p *StateProcessor) Process(block *types.Block, parent *types.Header, state
|
||||
context = NewEVMBlockContext(header, p.bc, nil)
|
||||
// Use the converted ethereum ChainConfig for EVM
|
||||
ethConfig = convertToEthChainConfig(p.config)
|
||||
vmenv = vm.NewEVM(context, statedb, ethConfig, cfg)
|
||||
signer = types.MakeSigner(ethConfig, header.Number, header.Time)
|
||||
txContext = vm.TxContext{} // Empty initial tx context
|
||||
vmenv = vm.NewEVM(context, txContext, statedb, ethConfig, cfg)
|
||||
signer = types.MakeSigner(p.config.ToEthChainConfig(), header.Number, header.Time)
|
||||
)
|
||||
if beaconRoot := block.BeaconRoot(); beaconRoot != nil {
|
||||
ProcessBeaconBlockRoot(*beaconRoot, vmenv, statedb)
|
||||
@@ -121,7 +123,7 @@ func applyTransaction(msg *Message, config *params.ChainConfig, gp *GasPool, sta
|
||||
// Create a new context to be used in the EVM environment.
|
||||
txContext := NewEVMTxContext(msg)
|
||||
// Update the evm with the new transaction context.
|
||||
evm.SetTxContext(txContext)
|
||||
evm.Reset(txContext, statedb)
|
||||
|
||||
// Apply the transaction to the current state (included in the env).
|
||||
result, err := ApplyMessage(evm, msg, gp)
|
||||
@@ -160,8 +162,8 @@ func applyTransaction(msg *Message, config *params.ChainConfig, gp *GasPool, sta
|
||||
}
|
||||
|
||||
// Set the receipt logs and create the bloom filter.
|
||||
receipt.Logs = statedb.GetLogs(tx.Hash(), blockNumber.Uint64(), blockHash, 0)
|
||||
receipt.Bloom = types.CreateBloom(receipt)
|
||||
receipt.Logs = statedb.GetLogs(tx.Hash(), blockNumber.Uint64(), blockHash)
|
||||
receipt.Bloom = types.CreateBloom(types.Receipts{receipt})
|
||||
receipt.BlockHash = blockHash
|
||||
receipt.BlockNumber = blockNumber
|
||||
receipt.TransactionIndex = uint(statedb.TxIndex())
|
||||
@@ -173,15 +175,14 @@ func applyTransaction(msg *Message, config *params.ChainConfig, gp *GasPool, sta
|
||||
// for the transaction, gas used and an error if the transaction failed,
|
||||
// indicating the block was invalid.
|
||||
func ApplyTransaction(config *params.ChainConfig, bc ChainContext, blockContext vm.BlockContext, gp *GasPool, statedb *state.StateDB, header *types.Header, tx *types.Transaction, usedGas *uint64, cfg vm.Config) (*types.Receipt, error) {
|
||||
msg, err := TransactionToMessage(tx, types.MakeSigner(convertToEthChainConfig(config), header.Number, header.Time), header.BaseFee)
|
||||
msg, err := TransactionToMessage(tx, types.MakeSigner(config.ToEthChainConfig(), header.Number, header.Time), header.BaseFee)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Create a new context to be used in the EVM environment
|
||||
txContext := NewEVMTxContext(msg)
|
||||
ethConfig := convertToEthChainConfig(config)
|
||||
vmenv := vm.NewEVM(blockContext, statedb, ethConfig, cfg)
|
||||
vmenv.SetTxContext(txContext)
|
||||
vmenv := vm.NewEVM(blockContext, txContext, statedb, ethConfig, cfg)
|
||||
return applyTransaction(msg, config, gp, statedb, header.Number, header.Hash(), tx, usedGas, vmenv)
|
||||
}
|
||||
|
||||
@@ -204,9 +205,9 @@ func ProcessBeaconBlockRoot(beaconRoot common.Hash, vmenv *vm.EVM, statedb *stat
|
||||
Data: beaconRoot[:],
|
||||
}
|
||||
// Update the evm with the new transaction context.
|
||||
vmenv.SetTxContext(NewEVMTxContext(msg))
|
||||
vmenv.Reset(NewEVMTxContext(msg), statedb)
|
||||
statedb.AddAddressToAccessList(beaconRootsAddr)
|
||||
// Call the beacon roots contract
|
||||
_, _, _ = vmenv.Call(msg.From, *msg.To, msg.Data, 30_000_000, common.U2560)
|
||||
_, _, _ = vmenv.Call(vm.AccountRef(msg.From), *msg.To, msg.Data, 30_000_000, uint256.NewInt(0))
|
||||
statedb.Finalise(true)
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"math/big"
|
||||
|
||||
"github.com/luxfi/geth/log"
|
||||
"github.com/luxfi/geth/core/tracing"
|
||||
"github.com/luxfi/evm/core/extstate"
|
||||
"github.com/luxfi/evm/core/state"
|
||||
"github.com/luxfi/evm/params"
|
||||
@@ -57,7 +56,7 @@ func ApplyPrecompileActivations(c *params.ChainConfig, parentTimestamp *uint64,
|
||||
// Set the nonce of the precompile's address (as is done when a contract is created) to ensure
|
||||
// that it is marked as non-empty and will not be cleaned up when the statedb is finalized.
|
||||
// SetNonce now requires a tracing.NonceChangeReason parameter
|
||||
statedb.SetNonce(module.Address, 1, tracing.NonceChangeUnspecified)
|
||||
statedb.SetNonce(module.Address, 1)
|
||||
// Set the code of the precompile's address to a non-zero length byte slice to ensure that the precompile
|
||||
// can be called from within Solidity contracts. Solidity adds a check before invoking a contract to ensure
|
||||
// that it does not attempt to invoke a non-existent contract.
|
||||
|
||||
+19
-18
@@ -40,7 +40,6 @@ import (
|
||||
ethparams "github.com/luxfi/geth/params"
|
||||
"github.com/holiman/uint256"
|
||||
"github.com/luxfi/geth/crypto/kzg4844"
|
||||
"github.com/luxfi/geth/core/tracing"
|
||||
)
|
||||
|
||||
// BigMin returns the smaller of x or y.
|
||||
@@ -344,7 +343,7 @@ func (st *StateTransition) buyGas() error {
|
||||
|
||||
st.initialGas = st.msg.GasLimit
|
||||
mgvalU256, _ := uint256.FromBig(mgval)
|
||||
st.state.SubBalance(st.msg.From, mgvalU256, tracing.BalanceDecreaseGasBuy)
|
||||
st.state.SubBalance(st.msg.From, mgvalU256)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -520,7 +519,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
|
||||
|
||||
// Check whether the init code size has been exceeded.
|
||||
if rulesExtra.IsDurango && contractCreation && len(msg.Data) > ethparams.MaxInitCodeSize {
|
||||
return nil, fmt.Errorf("%w: code size %v limit %v", vm.ErrMaxInitCodeSizeExceeded, len(msg.Data), ethparams.MaxInitCodeSize)
|
||||
return nil, fmt.Errorf("max init code size exceeded: code size %v limit %v", len(msg.Data), ethparams.MaxInitCodeSize)
|
||||
}
|
||||
|
||||
// Execute the preparatory steps for state transition which includes:
|
||||
@@ -528,16 +527,18 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
|
||||
// - reset transient storage(eip 1153)
|
||||
// Convert to ethereum Rules for Prepare call
|
||||
ethRules := ethparams.Rules{
|
||||
ChainID: rules.ChainID,
|
||||
IsHomestead: rules.IsHomestead,
|
||||
IsEIP150: rules.IsEIP150,
|
||||
IsEIP155: rules.IsEIP155,
|
||||
IsEIP158: rules.IsEIP158,
|
||||
IsByzantium: rules.IsByzantium,
|
||||
IsConstantinople: rules.IsConstantinople,
|
||||
IsPetersburg: rules.IsPetersburg,
|
||||
IsIstanbul: rules.IsIstanbul,
|
||||
IsCancun: rules.IsCancun,
|
||||
ChainID: rules.ChainID,
|
||||
EthRules: ethparams.EthRules{
|
||||
IsHomestead: rules.IsHomestead,
|
||||
IsEIP150: rules.IsEIP150,
|
||||
IsEIP155: rules.IsEIP155,
|
||||
IsEIP158: rules.IsEIP158,
|
||||
IsByzantium: rules.IsByzantium,
|
||||
IsConstantinople: rules.IsConstantinople,
|
||||
IsPetersburg: rules.IsPetersburg,
|
||||
IsIstanbul: rules.IsIstanbul,
|
||||
IsCancun: rules.IsCancun,
|
||||
},
|
||||
}
|
||||
// Get precompiles for ethereum rules
|
||||
var precompiles []common.Address
|
||||
@@ -551,11 +552,11 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
|
||||
vmerr error // vm errors do not effect consensus and are therefore not assigned to err
|
||||
)
|
||||
if contractCreation {
|
||||
ret, _, st.gasRemaining, vmerr = st.evm.Create(sender, msg.Data, st.gasRemaining, value)
|
||||
ret, _, st.gasRemaining, vmerr = st.evm.Create(vm.AccountRef(sender), msg.Data, st.gasRemaining, value)
|
||||
} else {
|
||||
// Increment the nonce for the next transaction
|
||||
st.state.SetNonce(msg.From, st.state.GetNonce(msg.From)+1, tracing.NonceChangeUnspecified)
|
||||
ret, st.gasRemaining, vmerr = st.evm.Call(sender, st.to(), msg.Data, st.gasRemaining, value)
|
||||
st.state.SetNonce(msg.From, st.state.GetNonce(msg.From)+1)
|
||||
ret, st.gasRemaining, vmerr = st.evm.Call(vm.AccountRef(sender), st.to(), msg.Data, st.gasRemaining, value)
|
||||
}
|
||||
price, overflow := uint256.FromBig(msg.GasPrice)
|
||||
if overflow {
|
||||
@@ -564,7 +565,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
|
||||
gasRefund := st.refundGas(rulesExtra.IsSubnetEVM)
|
||||
fee := new(uint256.Int).SetUint64(st.gasUsed())
|
||||
fee.Mul(fee, price)
|
||||
st.state.AddBalance(st.evm.Context.Coinbase, fee, tracing.BalanceIncreaseRewardTransactionFee)
|
||||
st.state.AddBalance(st.evm.Context.Coinbase, fee)
|
||||
|
||||
return &ExecutionResult{
|
||||
UsedGas: st.gasUsed(),
|
||||
@@ -589,7 +590,7 @@ func (st *StateTransition) refundGas(subnetEVM bool) uint64 {
|
||||
// Return ETH for remaining gas, exchanged at the original rate.
|
||||
remaining := uint256.NewInt(st.gasRemaining)
|
||||
remaining = remaining.Mul(remaining, uint256.MustFromBig(st.msg.GasPrice))
|
||||
st.state.AddBalance(st.msg.From, remaining, tracing.BalanceIncreaseGasReturn)
|
||||
st.state.AddBalance(st.msg.From, remaining)
|
||||
|
||||
// Also return remaining gas to the block gas counter so it is
|
||||
// available for the next transaction.
|
||||
|
||||
@@ -645,7 +645,7 @@ func TestSetPreferenceRewind(t *testing.T, create func(db ethdb.Database, gspec
|
||||
return fmt.Errorf("expected addr2 nonce: 0, found nonce: %d", nonce2)
|
||||
}
|
||||
balance2 := sdb.GetBalance(addr2)
|
||||
if balance2.Cmp(common.U2560) != 0 {
|
||||
if balance2.Cmp(uint256.NewInt(0)) != 0 {
|
||||
return fmt.Errorf("expected addr2 balance: 0, found balance %d", balance2)
|
||||
}
|
||||
return nil
|
||||
@@ -845,7 +845,7 @@ func TestBuildOnVariousStages(t *testing.T, create func(db ethdb.Database, gspec
|
||||
}
|
||||
|
||||
balance3 := sdb.GetBalance(addr3)
|
||||
expectedBalance3 := common.U2560
|
||||
expectedBalance3 := uint256.NewInt(0)
|
||||
if balance3.Cmp(expectedBalance3) != 0 {
|
||||
return fmt.Errorf("expected addr3 balance: %d, found balance: %d", expectedBalance3, balance3)
|
||||
}
|
||||
@@ -1115,7 +1115,7 @@ func TestAcceptBlockIdenticalStateRoot(t *testing.T, create func(db ethdb.Databa
|
||||
return fmt.Errorf("expected addr1 nonce: 2, found nonce: %d", nonce1)
|
||||
}
|
||||
balance1 := sdb.GetBalance(addr1)
|
||||
expectedBalance := common.U2560
|
||||
expectedBalance := uint256.NewInt(0)
|
||||
if balance1.Cmp(expectedBalance) != 0 {
|
||||
return fmt.Errorf("expected balance1: %d, found balance: %d", expectedBalance, balance1)
|
||||
}
|
||||
@@ -1283,7 +1283,7 @@ func TestReprocessAcceptBlockIdenticalStateRoot(t *testing.T, create func(db eth
|
||||
return fmt.Errorf("expected addr1 nonce: 2, found nonce: %d", nonce1)
|
||||
}
|
||||
balance1 := sdb.GetBalance(addr1)
|
||||
expectedBalance := common.U2560
|
||||
expectedBalance := uint256.NewInt(0)
|
||||
if balance1.Cmp(expectedBalance) != 0 {
|
||||
return fmt.Errorf("expected balance1: %d, found balance: %d", expectedBalance, balance1)
|
||||
}
|
||||
@@ -1324,7 +1324,7 @@ func TestGenerateChainInvalidBlockFee(t *testing.T, create func(db ethdb.Databas
|
||||
t.Cleanup(blockchain.Stop)
|
||||
|
||||
// This call generates a chain of 3 blocks.
|
||||
signer := types.LatestSigner(testConvertToEthChainConfig(params.TestChainConfig))
|
||||
signer := types.LatestSigner(params.TestChainConfig.ToEthChainConfig())
|
||||
_, _, _, err = GenerateChainWithGenesis(gspec, blockchain.engine, 3, extras.TestChainConfig.FeeConfig.TargetBlockRate-1, func(i int, gen *BlockGen) {
|
||||
tx := types.NewTx(&types.DynamicFeeTx{
|
||||
ChainID: params.TestChainConfig.ChainID,
|
||||
@@ -1365,7 +1365,7 @@ func TestInsertChainInvalidBlockFee(t *testing.T, create func(db ethdb.Database,
|
||||
t.Cleanup(blockchain.Stop)
|
||||
|
||||
// This call generates a chain of 3 blocks.
|
||||
signer := types.LatestSigner(testConvertToEthChainConfig(params.TestChainConfig))
|
||||
signer := types.LatestSigner(params.TestChainConfig.ToEthChainConfig())
|
||||
eng := dummy.NewFakerWithMode(dummy.Mode{ModeSkipBlockFee: true, ModeSkipCoinbase: true})
|
||||
_, chain, _, err := GenerateChainWithGenesis(gspec, eng, 3, extras.TestChainConfig.FeeConfig.TargetBlockRate-1, func(i int, gen *BlockGen) {
|
||||
tx := types.NewTx(&types.DynamicFeeTx{
|
||||
@@ -1409,7 +1409,7 @@ func TestInsertChainValidBlockFee(t *testing.T, create func(db ethdb.Database, g
|
||||
t.Cleanup(blockchain.Stop)
|
||||
|
||||
// This call generates a chain of 3 blocks.
|
||||
signer := types.LatestSigner(testConvertToEthChainConfig(params.TestChainConfig))
|
||||
signer := types.LatestSigner(params.TestChainConfig.ToEthChainConfig())
|
||||
tip := big.NewInt(50000 * params.GWei)
|
||||
transfer := big.NewInt(10000)
|
||||
_, chain, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, 3, extras.TestChainConfig.FeeConfig.TargetBlockRate-1, func(i int, gen *BlockGen) {
|
||||
@@ -1499,7 +1499,7 @@ func TestStatefulPrecompiles(t *testing.T, create func(db ethdb.Database, gspec
|
||||
}
|
||||
defer blockchain.Stop()
|
||||
|
||||
signer := types.LatestSigner(testConvertToEthChainConfig(params.TestChainConfig))
|
||||
signer := types.LatestSigner(params.TestChainConfig.ToEthChainConfig())
|
||||
tip := big.NewInt(50000 * params.GWei)
|
||||
|
||||
// Simple framework to add a test that the stateful precompile works as expected
|
||||
|
||||
@@ -89,7 +89,9 @@ func ActivateableEips() []string {
|
||||
|
||||
// NewEVM creates a new EVM instance.
|
||||
func NewEVM(blockCtx BlockContext, statedb StateDB, chainConfig *params.ChainConfig, config Config) *EVM {
|
||||
evm := vm.NewEVM(blockCtx, statedb, chainConfig, config)
|
||||
// Create an empty TxContext for backward compatibility
|
||||
txCtx := vm.TxContext{}
|
||||
evm := vm.NewEVM(blockCtx, txCtx, statedb, chainConfig, config)
|
||||
return &EVM{EVM: evm}
|
||||
}
|
||||
|
||||
@@ -128,6 +130,6 @@ func ConvertChainConfig(cfg *luxparams.ChainConfig) *params.ChainConfig {
|
||||
// NewEVMWithStateDB creates a new EVM with luxfi chainConfig and statedb
|
||||
func NewEVMWithStateDB(blockCtx BlockContext, txCtx TxContext, statedb *state.StateDB, chainConfig *luxparams.ChainConfig, config Config) *EVM {
|
||||
ethConfig := ConvertChainConfig(chainConfig)
|
||||
evm := vm.NewEVM(blockCtx, statedb, ethConfig, config)
|
||||
evm := vm.NewEVM(blockCtx, txCtx, statedb, ethConfig, config)
|
||||
return &EVM{EVM: evm}
|
||||
}
|
||||
@@ -28,6 +28,7 @@
|
||||
package ethclient
|
||||
|
||||
import (
|
||||
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
@@ -276,10 +277,12 @@ func (ec *client) getBlock(ctx context.Context, method string, args ...interface
|
||||
}
|
||||
txs[i] = tx.tx
|
||||
}
|
||||
return types.NewBlockWithHeader(head).WithBody(types.Body{
|
||||
// Create an ethereum Body type for WithBody
|
||||
ethBody := ethtypes.Body{
|
||||
Transactions: txs,
|
||||
Uncles: uncles,
|
||||
}), nil
|
||||
}
|
||||
return types.NewBlockWithHeader(head).WithBody(ethBody), nil
|
||||
}
|
||||
|
||||
// HeaderByHash returns the block header with the given hash.
|
||||
|
||||
@@ -2,11 +2,18 @@ module github.com/luxfi/evm
|
||||
|
||||
go 1.24.5
|
||||
|
||||
replace (
|
||||
github.com/crate-crypto/go-kzg-4844 => github.com/crate-crypto/go-kzg-4844 v1.1.0
|
||||
github.com/luxfi/geth => ../geth
|
||||
github.com/luxfi/netrunner => ../netrunner
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/VictoriaMetrics/fastcache v1.12.5
|
||||
github.com/davecgh/go-spew v1.1.1
|
||||
github.com/deckarep/golang-set/v2 v2.6.0
|
||||
github.com/docker/docker v28.3.2+incompatible
|
||||
github.com/ethereum/go-ethereum v1.16.1
|
||||
github.com/fjl/gencodec v0.1.1
|
||||
github.com/fsnotify/fsnotify v1.6.0
|
||||
github.com/go-cmd/cmd v1.4.1
|
||||
@@ -17,7 +24,7 @@ require (
|
||||
github.com/holiman/billy v0.0.0-20240216141850-2abb0c79d3c4
|
||||
github.com/holiman/bloomfilter/v2 v2.0.3
|
||||
github.com/holiman/uint256 v1.3.2
|
||||
github.com/luxfi/geth v0.15.7
|
||||
github.com/luxfi/geth v0.15.31
|
||||
github.com/luxfi/netrunner v1.7.7
|
||||
github.com/luxfi/node v1.13.9
|
||||
github.com/mattn/go-colorable v0.1.14
|
||||
@@ -58,12 +65,12 @@ require (
|
||||
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
|
||||
github.com/consensys/gnark-crypto v0.18.0 // indirect
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
|
||||
github.com/crate-crypto/go-eth-kzg v1.3.0 // indirect
|
||||
github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a // indirect
|
||||
github.com/crate-crypto/go-kzg-4844 v1.0.0 // indirect
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
|
||||
github.com/ethereum/c-kzg-4844 v1.0.0 // indirect
|
||||
github.com/ethereum/go-ethereum v1.14.12 // indirect
|
||||
github.com/ethereum/c-kzg-4844/v2 v2.1.0 // indirect
|
||||
github.com/ethereum/go-verkle v0.2.2 // indirect
|
||||
github.com/ferranbt/fastssz v0.1.2 // indirect
|
||||
github.com/garslo/gogen v0.0.0-20170306192744-1d203ffc1f61 // indirect
|
||||
github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 // indirect
|
||||
github.com/getsentry/sentry-go v0.27.0 // indirect
|
||||
@@ -84,10 +91,12 @@ require (
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.1 // indirect
|
||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||
github.com/klauspost/compress v1.18.0 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
|
||||
github.com/kr/pretty v0.3.1 // indirect
|
||||
github.com/kr/text v0.2.0 // indirect
|
||||
github.com/magiconair/properties v1.8.6 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.13 // indirect
|
||||
github.com/minio/sha256-simd v1.0.0 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/mitchellh/pointerstructure v1.2.1 // indirect
|
||||
github.com/moby/sys/reexec v0.1.0 // indirect
|
||||
|
||||
@@ -103,10 +103,10 @@ github.com/consensys/gnark-crypto v0.18.0 h1:vIye/FqI50VeAr0B3dx+YjeIvmc3LWz4yEf
|
||||
github.com/consensys/gnark-crypto v0.18.0/go.mod h1:L3mXGFTe1ZN+RSJ+CLjUt9x7PNdx8ubaYfDROyp2Z8c=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.7 h1:zbFlGlXEAKlwXpmvle3d8Oe3YnkKIK4xSRTd3sHPnBo=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.7/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
|
||||
github.com/crate-crypto/go-eth-kzg v1.3.0 h1:05GrhASN9kDAidaFJOda6A4BEvgvuXbazXg/0E3OOdI=
|
||||
github.com/crate-crypto/go-eth-kzg v1.3.0/go.mod h1:J9/u5sWfznSObptgfa92Jq8rTswn6ahQWEuiLHOjCUI=
|
||||
github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a h1:W8mUrRp6NOVl3J+MYp5kPMoUZPp7aOYHtaua31lwRHg=
|
||||
github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a/go.mod h1:sTwzHBvIzm2RfVCGNEBZgRyjwK40bVoun3ZnGOCafNM=
|
||||
github.com/crate-crypto/go-kzg-4844 v1.0.0 h1:TsSgHwrkTKecKJ4kadtHi4b3xHW5dCFUDFnUp1TsawI=
|
||||
github.com/crate-crypto/go-kzg-4844 v1.0.0/go.mod h1:1kMhvPgI0Ky3yIa+9lFySEBUBXkYxeOi8ZF1sYioxhc=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
@@ -129,12 +129,14 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
|
||||
github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po=
|
||||
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
|
||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||
github.com/ethereum/c-kzg-4844 v1.0.0 h1:0X1LBXxaEtYD9xsyj9B9ctQEZIpnvVDeoBx8aHEwTNA=
|
||||
github.com/ethereum/c-kzg-4844 v1.0.0/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0=
|
||||
github.com/ethereum/go-ethereum v1.14.12 h1:8hl57x77HSUo+cXExrURjU/w1VhL+ShCTJrTwcCQSe4=
|
||||
github.com/ethereum/go-ethereum v1.14.12/go.mod h1:RAC2gVMWJ6FkxSPESfbshrcKpIokgQKsVKmAuqdekDY=
|
||||
github.com/ethereum/c-kzg-4844/v2 v2.1.0 h1:gQropX9YFBhl3g4HYhwE70zq3IHFRgbbNPw0Shwzf5w=
|
||||
github.com/ethereum/c-kzg-4844/v2 v2.1.0/go.mod h1:TC48kOKjJKPbN7C++qIgt0TJzZ70QznYR7Ob+WXl57E=
|
||||
github.com/ethereum/go-ethereum v1.16.1 h1:7684NfKCb1+IChudzdKyZJ12l1Tq4ybPZOITiCDXqCk=
|
||||
github.com/ethereum/go-ethereum v1.16.1/go.mod h1:ngYIvmMAYdo4sGW9cGzLvSsPGhDOOzL0jK5S5iXpj0g=
|
||||
github.com/ethereum/go-verkle v0.2.2 h1:I2W0WjnrFUIzzVPwm8ykY+7pL2d4VhlsePn4j7cnFk8=
|
||||
github.com/ethereum/go-verkle v0.2.2/go.mod h1:M3b90YRnzqKyyzBEWJGqj8Qff4IDeXnzFw0P9bFw3uk=
|
||||
github.com/ferranbt/fastssz v0.1.2 h1:Dky6dXlngF6Qjc+EfDipAkE83N5I5DE68bY6O0VLNPk=
|
||||
github.com/ferranbt/fastssz v0.1.2/go.mod h1:X5UPrE2u1UJjxHA8X54u04SBwdAQjG2sFtWs39YxyWs=
|
||||
github.com/fjl/gencodec v0.1.1 h1:DhQY29Q6JLXB/GgMqE86NbOEuvckiYcJCbXFu02toms=
|
||||
github.com/fjl/gencodec v0.1.1/go.mod h1:chDHL3wKXuBgauP8x3XNZkl5EIAR5SoCTmmmDTZRzmw=
|
||||
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
|
||||
@@ -284,6 +286,9 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o
|
||||
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
|
||||
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
|
||||
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
|
||||
github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||
github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4=
|
||||
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
@@ -296,6 +301,8 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0
|
||||
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
|
||||
github.com/leanovate/gopter v0.2.11 h1:vRjThO1EKPb/1NsDXuDrzldR28RLkBflWYcU9CvzWu4=
|
||||
github.com/leanovate/gopter v0.2.11/go.mod h1:aK3tzZP/C+p1m3SPRE4SYZFGP7jjkuSI4f7Xvpt0S9c=
|
||||
github.com/luxfi/node v1.13.9 h1:D7P41v4SQ6ZTjUQ+9VpYWtofThYPhV8oI9dl7+SB/Is=
|
||||
github.com/luxfi/node v1.13.9/go.mod h1:AcNHZ2EmL3oYLlvTyiAXmItiZyziapHBZKzS2/UgUWI=
|
||||
github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo=
|
||||
github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
|
||||
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
|
||||
@@ -305,6 +312,8 @@ github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D
|
||||
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
|
||||
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/minio/sha256-simd v1.0.0 h1:v1ta+49hkWZyvaKwrQB8elexRqm6Y0aMLjCNsrYxo6g=
|
||||
github.com/minio/sha256-simd v1.0.0/go.mod h1:OuYzVNI5vcoYIAmbIvHPl3N3jUzVedXbKy5RFepssQM=
|
||||
github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
@@ -364,6 +373,8 @@ github.com/prometheus/common v0.62.0 h1:xasJaQlnWAeyHdUBeGjXmutelfJHWMRr+Fg4QszZ
|
||||
github.com/prometheus/common v0.62.0/go.mod h1:vyBcEuLSvWos9B1+CyL7JZ2up+uFzXhkqml0W5zIY1I=
|
||||
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
|
||||
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
|
||||
github.com/prysmaticlabs/gohashtree v0.0.1-alpha.0.20220714111606-acbb2962fb48 h1:cSo6/vk8YpvkLbk9v3FO97cakNmUoxwi2KMP8hd5WIw=
|
||||
github.com/prysmaticlabs/gohashtree v0.0.1-alpha.0.20220714111606-acbb2962fb48/go.mod h1:4pWaT30XoEx1j8KNJf3TV+E3mQkaufn7mf+jRNb/Fuk=
|
||||
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||
|
||||
@@ -20,11 +20,10 @@ func WithMetrics(t *testing.T) {
|
||||
t.Cleanup(func() {
|
||||
metricsLock.Unlock()
|
||||
})
|
||||
if metrics.Enabled() {
|
||||
if metrics.Enabled {
|
||||
return
|
||||
}
|
||||
// Enable metrics for the test
|
||||
// Note: There's no public way to disable metrics in go-ethereum v1.16.1
|
||||
// So we just enable it and leave it enabled
|
||||
metrics.Enable()
|
||||
// Note: metrics.Enabled is a global bool variable in newer versions
|
||||
metrics.Enabled = true
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ import (
|
||||
"github.com/luxfi/evm/precompile/modules"
|
||||
"github.com/luxfi/evm/precompile/precompileconfig"
|
||||
"github.com/luxfi/evm/utils"
|
||||
ethparams "github.com/ethereum/go-ethereum/params"
|
||||
)
|
||||
|
||||
// Type aliases for extras package types
|
||||
@@ -271,6 +272,26 @@ func (c ChainConfig) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(raw)
|
||||
}
|
||||
|
||||
// ToEthChainConfig converts Lux ChainConfig to ethereum ChainConfig
|
||||
func (c *ChainConfig) ToEthChainConfig() *ethparams.ChainConfig {
|
||||
return ðparams.ChainConfig{
|
||||
ChainID: c.ChainID,
|
||||
HomesteadBlock: c.HomesteadBlock,
|
||||
EIP150Block: c.EIP150Block,
|
||||
EIP155Block: c.EIP155Block,
|
||||
EIP158Block: c.EIP158Block,
|
||||
ByzantiumBlock: c.ByzantiumBlock,
|
||||
ConstantinopleBlock: c.ConstantinopleBlock,
|
||||
PetersburgBlock: c.PetersburgBlock,
|
||||
IstanbulBlock: c.IstanbulBlock,
|
||||
MuirGlacierBlock: c.MuirGlacierBlock,
|
||||
BerlinBlock: c.BerlinBlock,
|
||||
LondonBlock: c.LondonBlock,
|
||||
ShanghaiTime: c.ShanghaiTime,
|
||||
CancunTime: c.CancunTime,
|
||||
}
|
||||
}
|
||||
|
||||
// Description returns a human-readable description of ChainConfig.
|
||||
func (c *ChainConfig) Description() string {
|
||||
var banner string
|
||||
|
||||
+2
-2
@@ -15,8 +15,8 @@ type RequestHandlerStats interface {
|
||||
}
|
||||
|
||||
type requestHandlerStats struct {
|
||||
timeUntilDeadline *metrics.Timer
|
||||
droppedRequests *metrics.Counter
|
||||
timeUntilDeadline metrics.Timer
|
||||
droppedRequests metrics.Counter
|
||||
}
|
||||
|
||||
func (h *requestHandlerStats) IncDeadlineDroppedRequest() {
|
||||
|
||||
@@ -29,13 +29,13 @@ type MessageMetric interface {
|
||||
}
|
||||
|
||||
type messageMetric struct {
|
||||
requested *metrics.Counter // Number of times a request has been sent
|
||||
succeeded *metrics.Counter // Number of times a request has succeeded
|
||||
failed *metrics.Counter // Number of times a request failed (does not include invalid responses)
|
||||
invalidResponse *metrics.Counter // Number of times a request failed due to an invalid response
|
||||
received *metrics.Counter // Number of items that have been received
|
||||
requested metrics.Counter // Number of times a request has been sent
|
||||
succeeded metrics.Counter // Number of times a request has succeeded
|
||||
failed metrics.Counter // Number of times a request failed (does not include invalid responses)
|
||||
invalidResponse metrics.Counter // Number of times a request failed due to an invalid response
|
||||
received metrics.Counter // Number of items that have been received
|
||||
|
||||
requestLatency *metrics.Timer // Latency for this request
|
||||
requestLatency metrics.Timer // Latency for this request
|
||||
}
|
||||
|
||||
func NewMessageMetric(name string) MessageMetric {
|
||||
|
||||
@@ -52,36 +52,36 @@ type LeafsRequestHandlerStats interface {
|
||||
|
||||
type handlerStats struct {
|
||||
// BlockRequestHandler metrics
|
||||
blockRequest *metrics.Counter
|
||||
missingBlockHash *metrics.Counter
|
||||
blockRequest metrics.Counter
|
||||
missingBlockHash metrics.Counter
|
||||
blocksReturned metrics.Histogram
|
||||
blockRequestProcessingTime *metrics.Timer
|
||||
blockRequestProcessingTime metrics.Timer
|
||||
|
||||
// CodeRequestHandler stats
|
||||
codeRequest *metrics.Counter
|
||||
missingCodeHash *metrics.Counter
|
||||
tooManyHashesRequested *metrics.Counter
|
||||
duplicateHashesRequested *metrics.Counter
|
||||
codeRequest metrics.Counter
|
||||
missingCodeHash metrics.Counter
|
||||
tooManyHashesRequested metrics.Counter
|
||||
duplicateHashesRequested metrics.Counter
|
||||
codeBytesReturned metrics.Histogram
|
||||
codeReadDuration *metrics.Timer
|
||||
codeReadDuration metrics.Timer
|
||||
|
||||
// LeafsRequestHandler stats
|
||||
leafsRequest *metrics.Counter
|
||||
invalidLeafsRequest *metrics.Counter
|
||||
leafsRequest metrics.Counter
|
||||
invalidLeafsRequest metrics.Counter
|
||||
leafsReturned metrics.Histogram
|
||||
leafsRequestProcessingTime *metrics.Timer
|
||||
leafsReadTime *metrics.Timer
|
||||
snapshotReadTime *metrics.Timer
|
||||
generateRangeProofTime *metrics.Timer
|
||||
leafsRequestProcessingTime metrics.Timer
|
||||
leafsReadTime metrics.Timer
|
||||
snapshotReadTime metrics.Timer
|
||||
generateRangeProofTime metrics.Timer
|
||||
proofValsReturned metrics.Histogram
|
||||
missingRoot *metrics.Counter
|
||||
trieError *metrics.Counter
|
||||
proofError *metrics.Counter
|
||||
snapshotReadError *metrics.Counter
|
||||
snapshotReadAttempt *metrics.Counter
|
||||
snapshotReadSuccess *metrics.Counter
|
||||
snapshotSegmentValid *metrics.Counter
|
||||
snapshotSegmentInvalid *metrics.Counter
|
||||
missingRoot metrics.Counter
|
||||
trieError metrics.Counter
|
||||
proofError metrics.Counter
|
||||
snapshotReadError metrics.Counter
|
||||
snapshotReadAttempt metrics.Counter
|
||||
snapshotReadSuccess metrics.Counter
|
||||
snapshotSegmentValid metrics.Counter
|
||||
snapshotSegmentInvalid metrics.Counter
|
||||
}
|
||||
|
||||
func (h *handlerStats) IncBlockRequest() {
|
||||
|
||||
@@ -38,14 +38,16 @@ import (
|
||||
"github.com/luxfi/geth/log"
|
||||
"github.com/luxfi/geth/trie/trienode"
|
||||
"github.com/luxfi/geth/triedb/database"
|
||||
ethpathdb "github.com/luxfi/geth/triedb/pathdb"
|
||||
"github.com/luxfi/evm/params"
|
||||
)
|
||||
|
||||
// Type aliases for compatibility
|
||||
type (
|
||||
StateSetWithOrigin = ethpathdb.StateSetWithOrigin
|
||||
)
|
||||
// StateSetWithOrigin wraps the state set with origin meta
|
||||
type StateSetWithOrigin struct {
|
||||
AccountOrigin map[common.Address][]byte
|
||||
StorageOrigin map[common.Address]map[common.Hash][]byte
|
||||
AccountData map[common.Address][]byte
|
||||
StorageData map[common.Address]map[common.Hash][]byte
|
||||
}
|
||||
|
||||
// triestate compatibility wrapper
|
||||
type triestateCompat struct{}
|
||||
|
||||
@@ -152,9 +152,9 @@ func (dl *diskLayer) Node(owner common.Hash, path []byte, hash common.Hash) ([]b
|
||||
nHash common.Hash
|
||||
)
|
||||
if owner == (common.Hash{}) {
|
||||
nBlob = rawdb.ReadAccountTrieNode(dl.db.diskdb, path)
|
||||
nBlob, _ = rawdb.ReadAccountTrieNode(dl.db.diskdb, path)
|
||||
} else {
|
||||
nBlob = rawdb.ReadStorageTrieNode(dl.db.diskdb, owner, path)
|
||||
nBlob, _ = rawdb.ReadStorageTrieNode(dl.db.diskdb, owner, path)
|
||||
}
|
||||
if len(nBlob) > 0 {
|
||||
nHash = crypto.Keccak256Hash(nBlob)
|
||||
|
||||
@@ -124,7 +124,7 @@ func (db *Database) loadJournal(diskRoot common.Hash) (layer, error) {
|
||||
// loadLayers loads a pre-existing state layer backed by a key-value store.
|
||||
func (db *Database) loadLayers() layer {
|
||||
// Retrieve the root node of persistent state.
|
||||
rootData := rawdb.ReadAccountTrieNode(db.diskdb, nil)
|
||||
rootData, _ := rawdb.ReadAccountTrieNode(db.diskdb, nil)
|
||||
var root common.Hash
|
||||
if len(rootData) > 0 {
|
||||
root = crypto.Keccak256Hash(rootData)
|
||||
@@ -368,7 +368,7 @@ func (db *Database) Journal(root common.Hash) error {
|
||||
}
|
||||
// The stored state in disk might be empty, convert the
|
||||
// root to emptyRoot in this case.
|
||||
rootData := rawdb.ReadAccountTrieNode(db.diskdb, nil)
|
||||
rootData, _ := rawdb.ReadAccountTrieNode(db.diskdb, nil)
|
||||
var diskroot common.Hash
|
||||
if len(rootData) > 0 {
|
||||
diskroot = crypto.Keccak256Hash(rootData)
|
||||
|
||||
@@ -167,9 +167,9 @@ func (b *nodebuffer) revert(db ethdb.KeyValueReader, nodes map[common.Hash]map[s
|
||||
var nhash common.Hash
|
||||
var nodeData []byte
|
||||
if owner == (common.Hash{}) {
|
||||
nodeData = rawdb.ReadAccountTrieNode(db, []byte(path))
|
||||
nodeData, _ = rawdb.ReadAccountTrieNode(db, []byte(path))
|
||||
} else {
|
||||
nodeData = rawdb.ReadStorageTrieNode(db, owner, []byte(path))
|
||||
nodeData, _ = rawdb.ReadStorageTrieNode(db, owner, []byte(path))
|
||||
}
|
||||
if len(nodeData) > 0 {
|
||||
nhash = crypto.Keccak256Hash(nodeData)
|
||||
|
||||
Reference in New Issue
Block a user