diff options
Diffstat (limited to 'plugin/evm')
-rw-r--r-- | plugin/evm/block.go | 20 | ||||
-rw-r--r-- | plugin/evm/vm.go | 33 |
2 files changed, 41 insertions, 12 deletions
diff --git a/plugin/evm/block.go b/plugin/evm/block.go index 5a0d377..08ef231 100644 --- a/plugin/evm/block.go +++ b/plugin/evm/block.go @@ -6,9 +6,9 @@ package evm import ( "errors" "fmt" + "math/big" "github.com/ava-labs/coreth/core/types" - "github.com/ava-labs/coreth/params" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/rlp" @@ -85,9 +85,11 @@ func (b *Block) Verify() error { // Only enforce a minimum fee when bootstrapping has finished if b.vm.ctx.IsBootstrapped() { // Ensure the minimum gas price is paid for every transaction + timestamp := b.ethBlock.Header().Time + minGasPrice := b.vm.minGasPrice.GetMin(new(big.Int).SetUint64(timestamp)) for _, tx := range b.ethBlock.Transactions() { - if tx.GasPrice().Cmp(params.MinGasPrice) < 0 { - return errInvalidBlock + if tx.GasPrice().Cmp(minGasPrice) < 0 { + return fmt.Errorf("block contains tx %s with gas price too low (%d < %d), timestamp: %d", tx.Hash(), tx.GasPrice(), minGasPrice, timestamp) } } } @@ -139,17 +141,21 @@ func (b *Block) Verify() error { } utx := tx.UnsignedTx.(UnsignedAtomicTx) - if utx.SemanticVerify(vm, tx) != nil { - return errInvalidBlock + if err := utx.SemanticVerify(vm, tx); err != nil { + return fmt.Errorf("block atomic tx failed verification due to: %w", err) } bc := vm.chain.BlockChain() _, _, _, err = bc.Processor().Process(b.ethBlock, pState, *bc.GetVMConfig()) if err != nil { - return errInvalidBlock + return fmt.Errorf("block failed processing due to: %w", err) } } _, err := b.vm.chain.InsertChain([]*types.Block{b.ethBlock}) - return err + if err != nil { + return fmt.Errorf("failed to insert block into chain due to: %w", err) + } + + return nil } // Bytes implements the snowman.Block interface diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index 9f5607a..ac1eb56 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -185,6 +185,8 @@ type VM struct { shutdownWg sync.WaitGroup fx secp256k1fx.Fx + + minGasPrice params.GasPrice } func (vm *VM) getAtomicTx(block *types.Block) *Tx { @@ -262,13 +264,34 @@ func (vm *VM) Initialize( config.Miner.ManualMining = true config.Miner.DisableUncle = true - // Set minimum price for mining and default gas price oracle value to the min - // gas price to prevent so transactions and blocks all use the correct fees - config.Miner.GasPrice = params.MinGasPrice + // Set minimum gas price and launch goroutine to sleep until + // network upgrade when the gas price must be changed + vm.minGasPrice = params.NewGasPrice(g.Config.ApricotBlockTimestamp) + if g.Config.ApricotBlockTimestamp == nil { + config.Miner.GasPrice = params.ApricotMinGasPrice + config.GPO.Default = params.ApricotMinGasPrice + config.TxPool.PriceLimit = params.ApricotMinGasPrice.Uint64() + } else { + apricotTime := time.Unix(g.Config.ApricotBlockTimestamp.Int64(), 0) + if time.Now().Before(apricotTime) { + config.Miner.GasPrice = params.LaunchMinGasPrice + config.GPO.Default = params.LaunchMinGasPrice + config.TxPool.PriceLimit = params.LaunchMinGasPrice.Uint64() + + go func() { + time.Sleep(time.Until(apricotTime)) + + vm.chain.SetGasPrice(params.ApricotMinGasPrice) + }() + } else { + config.Miner.GasPrice = params.ApricotMinGasPrice + config.GPO.Default = params.ApricotMinGasPrice + config.TxPool.PriceLimit = params.ApricotMinGasPrice.Uint64() + } + } + config.RPCGasCap = vm.CLIConfig.RPCGasCap config.RPCTxFeeCap = vm.CLIConfig.RPCTxFeeCap - config.GPO.Default = params.MinGasPrice - config.TxPool.PriceLimit = params.MinGasPrice.Uint64() config.TxPool.NoLocals = true if err := config.SetGCMode("archive"); err != nil { |