Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove old rules #738

Draft
wants to merge 3 commits into
base: remove-deprecated-apis
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 27 additions & 30 deletions consensus/dummy/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,42 +450,39 @@ func (eng *DummyEngine) FinalizeAndAssemble(chain consensus.ChainHeaderReader, h
return nil, err
}
}
if chain.Config().IsApricotPhase4(header.Time) {
header.ExtDataGasUsed = extDataGasUsed
if header.ExtDataGasUsed == nil {
header.ExtDataGasUsed = new(big.Int).Set(common.Big0)
}
blockGasCostStep := ApricotPhase4BlockGasCostStep
if chain.Config().IsApricotPhase5(header.Time) {
blockGasCostStep = ApricotPhase5BlockGasCostStep
}
// Calculate the required block gas cost for this block.
header.BlockGasCost = calcBlockGasCost(
ApricotPhase4TargetBlockRate,
ApricotPhase4MinBlockGasCost,
ApricotPhase4MaxBlockGasCost,
blockGasCostStep,
parent.BlockGasCost,
parent.Time, header.Time,
)
// Verify that this block covers the block fee.
if err := eng.verifyBlockFee(
header.BaseFee,
header.BlockGasCost,
txs,
receipts,
contribution,
); err != nil {
return nil, err
}

header.ExtDataGasUsed = extDataGasUsed
if header.ExtDataGasUsed == nil {
header.ExtDataGasUsed = new(big.Int).Set(common.Big0)
}
blockGasCostStep := ApricotPhase5BlockGasCostStep
// Calculate the required block gas cost for this block.
header.BlockGasCost = calcBlockGasCost(
ApricotPhase4TargetBlockRate,
ApricotPhase4MinBlockGasCost,
ApricotPhase4MaxBlockGasCost,
blockGasCostStep,
parent.BlockGasCost,
parent.Time, header.Time,
)
// Verify that this block covers the block fee.
if err := eng.verifyBlockFee(
header.BaseFee,
header.BlockGasCost,
txs,
receipts,
contribution,
); err != nil {
return nil, err
}

// commit the final state root
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))
header.Root = state.IntermediateRoot(true)

// Header seems complete, assemble into a block and return
return types.NewBlockWithExtData(
header, txs, uncles, receipts, trie.NewStackTrie(nil),
extraData, chain.Config().IsApricotPhase1(header.Time),
extraData, true,
), nil
}

Expand Down
5 changes: 0 additions & 5 deletions consensus/dummy/dynamic_fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,7 @@ func calcBlockGasCost(
// subsidize the inclusion of low tip paying transactions. The only
// correctness check performed is that the sum of all tips is >= the
// required block fee.
//
// This function will return nil for all return values prior to Apricot Phase 4.
func MinRequiredTip(config *params.ChainConfig, header *types.Header) (*big.Int, error) {
if !config.IsApricotPhase4(header.Time) {
return nil, nil
}
if header.BaseFee == nil {
return nil, errBaseFeeNil
}
Expand Down
28 changes: 11 additions & 17 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,18 +330,14 @@ func (w *worker) applyTransaction(env *environment, tx *types.Transaction, coinb
blockContext vm.BlockContext
)

if env.rules.IsDurango {
results, err := core.CheckPredicates(env.rules, env.predicateContext, tx)
if err != nil {
log.Debug("Transaction predicate failed verification in miner", "tx", tx.Hash(), "err", err)
return nil, err
}
env.predicateResults.SetTxResults(tx.Hash(), results)

blockContext = core.NewEVMBlockContextWithPredicateResults(env.header, w.chain, &coinbase, env.predicateResults)
} else {
blockContext = core.NewEVMBlockContext(env.header, w.chain, &coinbase)
results, err := core.CheckPredicates(env.rules, env.predicateContext, tx)
if err != nil {
log.Debug("Transaction predicate failed verification in miner", "tx", tx.Hash(), "err", err)
return nil, err
}
env.predicateResults.SetTxResults(tx.Hash(), results)

blockContext = core.NewEVMBlockContextWithPredicateResults(env.header, w.chain, &coinbase, env.predicateResults)

receipt, err := core.ApplyTransaction(w.chainConfig, w.chain, blockContext, env.gasPool, env.state, env.header, tx, &env.header.GasUsed, *w.chain.GetVMConfig())
if err != nil {
Expand Down Expand Up @@ -460,13 +456,11 @@ func (w *worker) commitTransactions(env *environment, plainTxs, blobTxs *transac
// commit runs any post-transaction state modifications, assembles the final block
// and commits new work if consensus engine is running.
func (w *worker) commit(env *environment) (*types.Block, error) {
if env.rules.IsDurango {
predicateResultsBytes, err := env.predicateResults.Bytes()
if err != nil {
return nil, fmt.Errorf("failed to marshal predicate results: %w", err)
}
env.header.Extra = append(env.header.Extra, predicateResultsBytes...)
predicateResultsBytes, err := env.predicateResults.Bytes()
if err != nil {
return nil, fmt.Errorf("failed to marshal predicate results: %w", err)
}
env.header.Extra = append(env.header.Extra, predicateResultsBytes...)
// Deep copy receipts here to avoid interaction between different tasks.
receipts := copyReceipts(env.receipts)
block, err := w.engine.FinalizeAndAssemble(w.chain, env.header, env.parent, env.state, env.txs, nil, receipts)
Expand Down
57 changes: 24 additions & 33 deletions plugin/evm/atomic/export_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
var (
_ UnsignedAtomicTx = &UnsignedExportTx{}
_ secp256k1fx.UnsignedTx = &UnsignedExportTx{}
ErrExportNonAVAXInputBanff = errors.New("export input cannot contain non-AVAX in Banff")
ErrExportNonAVAXOutputBanff = errors.New("export output cannot contain non-AVAX in Banff")
ErrExportNonAVAXInput = errors.New("export input cannot contain non-AVAX")
ErrExportNonAVAXOutput = errors.New("export output cannot contain non-AVAX")
ErrNoExportOutputs = errors.New("tx has no export outputs")
errPublicKeySignatureMismatch = errors.New("signature doesn't match public key")
errOverflowExport = errors.New("overflow when computing export amount + txFee")

Check failure on line 38 in plugin/evm/atomic/export_tx.go

View workflow job for this annotation

GitHub Actions / Lint

var `errOverflowExport` is unused (unused)
errInsufficientFunds = errors.New("insufficient funds")
errInvalidNonce = errors.New("invalid nonce")
)
Expand Down Expand Up @@ -103,8 +103,8 @@
if err := in.Verify(); err != nil {
return err
}
if rules.IsBanff && in.AssetID != ctx.AVAXAssetID {
return ErrExportNonAVAXInputBanff
if in.AssetID != ctx.AVAXAssetID {
return ErrExportNonAVAXInput
}
}

Expand All @@ -116,8 +116,8 @@
if assetID != ctx.AVAXAssetID && utx.DestinationChain == constants.PlatformChainID {
return ErrWrongChainID
}
if rules.IsBanff && assetID != ctx.AVAXAssetID {
return ErrExportNonAVAXOutputBanff
if assetID != ctx.AVAXAssetID {
return ErrExportNonAVAXOutput
}
}
if !avax.IsSortedTransferableOutputs(utx.ExportedOutputs, Codec) {
Expand Down Expand Up @@ -311,35 +311,26 @@
err error
)

switch {
case rules.IsApricotPhase3:
utx := &UnsignedExportTx{
NetworkID: ctx.NetworkID,
BlockchainID: ctx.ChainID,
DestinationChain: chainID,
Ins: ins,
ExportedOutputs: outs,
}
tx := &Tx{UnsignedAtomicTx: utx}
if err := tx.Sign(Codec, nil); err != nil {
return nil, err
}

var cost uint64
cost, err = tx.GasUsed(rules.IsApricotPhase5)
if err != nil {
return nil, err
}
// Create the temp transaction to get the cost
tempUtx := &UnsignedExportTx{
NetworkID: ctx.NetworkID,
BlockchainID: ctx.ChainID,
DestinationChain: chainID,
Ins: ins,
ExportedOutputs: outs,
}
tempTx := &Tx{UnsignedAtomicTx: tempUtx}
if err := tempTx.Sign(Codec, nil); err != nil {
return nil, err
}

avaxIns, avaxSigners, err = GetSpendableAVAXWithFee(ctx, state, keys, amount, cost, baseFee)
default:
var avaxNeeded uint64
avaxNeeded, err = math.Add(amount, params.AvalancheAtomicTxFee)
if err != nil {
return nil, errOverflowExport
}
avaxIns, avaxSigners, err = GetSpendableFunds(ctx, state, keys, avaxNeeded)
var cost uint64
cost, err = tempTx.GasUsed(true)
if err != nil {
return nil, err
}

avaxIns, avaxSigners, err = GetSpendableAVAXWithFee(ctx, state, keys, amount, cost, baseFee)
if err != nil {
return nil, fmt.Errorf("couldn't generate tx inputs/signers: %w", err)
}
Expand Down
96 changes: 45 additions & 51 deletions plugin/evm/atomic/import_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ import (
)

var (
_ UnsignedAtomicTx = &UnsignedImportTx{}
_ secp256k1fx.UnsignedTx = &UnsignedImportTx{}
ErrImportNonAVAXInputBanff = errors.New("import input cannot contain non-AVAX in Banff")
ErrImportNonAVAXOutputBanff = errors.New("import output cannot contain non-AVAX in Banff")
ErrNoImportInputs = errors.New("tx has no imported inputs")
ErrConflictingAtomicInputs = errors.New("invalid block due to conflicting atomic inputs")
ErrWrongChainID = errors.New("tx has wrong chain ID")
ErrNoEVMOutputs = errors.New("tx has no EVM outputs")
ErrInputsNotSortedUnique = errors.New("inputs not sorted and unique")
ErrOutputsNotSortedUnique = errors.New("outputs not sorted and unique")
ErrOutputsNotSorted = errors.New("tx outputs not sorted")
ErrAssetIDMismatch = errors.New("asset IDs in the input don't match the utxo")
errNilBaseFeeApricotPhase3 = errors.New("nil base fee is invalid after apricotPhase3")
errInsufficientFundsForFee = errors.New("insufficient AVAX funds to pay transaction fee")
errRejectedParent = errors.New("rejected parent")
_ UnsignedAtomicTx = &UnsignedImportTx{}
_ secp256k1fx.UnsignedTx = &UnsignedImportTx{}
ErrImportNonAVAXInput = errors.New("import input cannot contain non-AVAX")
ErrImportNonAVAXOutput = errors.New("import output cannot contain non-AVAX")
ErrNoImportInputs = errors.New("tx has no imported inputs")
ErrConflictingAtomicInputs = errors.New("invalid block due to conflicting atomic inputs")
ErrWrongChainID = errors.New("tx has wrong chain ID")
ErrNoEVMOutputs = errors.New("tx has no EVM outputs")
ErrInputsNotSortedUnique = errors.New("inputs not sorted and unique")
ErrOutputsNotSortedUnique = errors.New("outputs not sorted and unique")
ErrOutputsNotSorted = errors.New("tx outputs not sorted")
ErrAssetIDMismatch = errors.New("asset IDs in the input don't match the utxo")
errNilBaseFeeApricotPhase3 = errors.New("nil base fee is invalid after apricotPhase3")
errInsufficientFundsForFee = errors.New("insufficient AVAX funds to pay transaction fee")
errRejectedParent = errors.New("rejected parent")
)

// UnsignedImportTx is an unsigned ImportTx
Expand Down Expand Up @@ -104,17 +104,17 @@ func (utx *UnsignedImportTx) Verify(
if err := out.Verify(); err != nil {
return fmt.Errorf("EVM Output failed verification: %w", err)
}
if rules.IsBanff && out.AssetID != ctx.AVAXAssetID {
return ErrImportNonAVAXOutputBanff
if out.AssetID != ctx.AVAXAssetID {
return ErrImportNonAVAXOutput
}
}

for _, in := range utx.ImportedInputs {
if err := in.Verify(); err != nil {
return fmt.Errorf("atomic input failed verification: %w", err)
}
if rules.IsBanff && in.AssetID() != ctx.AVAXAssetID {
return ErrImportNonAVAXInputBanff
if in.AssetID() != ctx.AVAXAssetID {
return ErrImportNonAVAXInput
}
}
if !utils.IsSortedAndUnique(utx.ImportedInputs) {
Expand Down Expand Up @@ -345,40 +345,34 @@ func NewImportTx(
txFeeWithoutChange uint64
txFeeWithChange uint64
)
switch {
case rules.IsApricotPhase3:
if baseFee == nil {
return nil, errNilBaseFeeApricotPhase3
}
utx := &UnsignedImportTx{
NetworkID: ctx.NetworkID,
BlockchainID: ctx.ChainID,
Outs: outs,
ImportedInputs: importedInputs,
SourceChain: chainID,
}
tx := &Tx{UnsignedAtomicTx: utx}
if err := tx.Sign(Codec, nil); err != nil {
return nil, err
}
if baseFee == nil {
return nil, errNilBaseFeeApricotPhase3
}
tempUtx := &UnsignedImportTx{
NetworkID: ctx.NetworkID,
BlockchainID: ctx.ChainID,
Outs: outs,
ImportedInputs: importedInputs,
SourceChain: chainID,
}
tempTx := &Tx{UnsignedAtomicTx: tempUtx}
if err := tempTx.Sign(Codec, nil); err != nil {
return nil, err
}

gasUsedWithoutChange, err := tx.GasUsed(rules.IsApricotPhase5)
if err != nil {
return nil, err
}
gasUsedWithChange := gasUsedWithoutChange + EVMOutputGas
gasUsedWithoutChange, err := tempTx.GasUsed(true)
if err != nil {
return nil, err
}
gasUsedWithChange := gasUsedWithoutChange + EVMOutputGas

txFeeWithoutChange, err = CalculateDynamicFee(gasUsedWithoutChange, baseFee)
if err != nil {
return nil, err
}
txFeeWithChange, err = CalculateDynamicFee(gasUsedWithChange, baseFee)
if err != nil {
return nil, err
}
case rules.IsApricotPhase2:
txFeeWithoutChange = params.AvalancheAtomicTxFee
txFeeWithChange = params.AvalancheAtomicTxFee
txFeeWithoutChange, err = CalculateDynamicFee(gasUsedWithoutChange, baseFee)
if err != nil {
return nil, err
}
txFeeWithChange, err = CalculateDynamicFee(gasUsedWithChange, baseFee)
if err != nil {
return nil, err
}

// AVAX output
Expand Down
4 changes: 2 additions & 2 deletions plugin/evm/import_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ func TestImportTxVerify(t *testing.T) {
},
ctx: ctx,
rules: banffRules,
expectedErr: atomic.ErrImportNonAVAXInputBanff.Error(),
expectedErr: atomic.ErrImportNonAVAXInput.Error(),
},
"non-AVAX output Banff": {
generate: func(t *testing.T) atomic.UnsignedAtomicTx {
Expand All @@ -414,7 +414,7 @@ func TestImportTxVerify(t *testing.T) {
},
ctx: ctx,
rules: banffRules,
expectedErr: atomic.ErrImportNonAVAXOutputBanff.Error(),
expectedErr: atomic.ErrImportNonAVAXOutput.Error(),
},
}
for name, test := range tests {
Expand Down
Loading
Loading