From 98e1e9f1f169fd9c8a4e5a7ca9547c77d923c4fc Mon Sep 17 00:00:00 2001 From: Aaron Buchwald Date: Sun, 20 Sep 2020 12:00:12 -0400 Subject: Move copied and hacked lists into notes directory --- copied-list.txt | 107 -------------------------------------------------- hacked-list.txt | 43 -------------------- notes/copied-list.txt | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++ notes/hacked-list.txt | 43 ++++++++++++++++++++ 4 files changed, 150 insertions(+), 150 deletions(-) delete mode 100644 copied-list.txt delete mode 100644 hacked-list.txt create mode 100644 notes/copied-list.txt create mode 100644 notes/hacked-list.txt diff --git a/copied-list.txt b/copied-list.txt deleted file mode 100644 index 94353ff..0000000 --- a/copied-list.txt +++ /dev/null @@ -1,107 +0,0 @@ -./consensus/clique/api.go -./consensus/clique/snapshot.go -./consensus/errors.go -./consensus/ethash/algorithm.go -./consensus/ethash/api.go -./consensus/ethash/ethash.go -./consensus/ethash/sealer.go -./consensus/misc/dao.go -./consensus/misc/forks.go -./core/blockchain_insert.go -./core/blocks.go -./core/block_validator.go -./core/bloombits/doc.go -./core/bloombits/generator.go -./core/bloombits/matcher.go -./core/bloombits/scheduler.go -./core/chain_indexer.go -./core/error.go -./core/gaspool.go -./core/genesis_alloc.go -./core/headerchain.go -./core/mkalloc.go -./core/rawdb/accessors_indexes.go -./core/rawdb/accessors_metadata.go -./core/rawdb/database.go -./core/rawdb/freezer.go -./core/rawdb/freezer_reinit.go -./core/rawdb/freezer_table.go -./core/rawdb/schema.go -./core/rawdb/table.go -./core/state/database.go -./core/state/dump.go -./core/state/iterator.go -./core/state_prefetcher.go -./core/state/sync.go -./core/state_transition.go -./core/tx_cacher.go -./core/tx_journal.go -./core/tx_list.go -./core/tx_noncer.go -./core/types/bloom9.go -./core/types/derive_sha.go -./core/types/gen_header_json.go -./core/types/gen_log_json.go -./core/types/gen_receipt_json.go -./core/types/gen_tx_json.go -./core/types.go -./core/types/log.go -./core/types/receipt.go -./core/types/transaction.go -./core/types/transaction_signing.go -./core/vm/analysis.go -./core/vm/common.go -./core/vm/contract.go -./core/vm/contracts.go -./core/vm/doc.go -./core/vm/eips.go -./core/vm/gas.go -./core/vm/gas_table.go -./core/vm/gen_structlog.go -./core/vm/intpool.go -./core/vm/int_pool_verifier_empty.go -./core/vm/int_pool_verifier.go -./core/vm/logger.go -./core/vm/logger_json.go -./core/vm/memory.go -./core/vm/stack.go -./core/vm/stack_table.go -./eth/bloombits.go -./eth/filters/api.go -./eth/filters/filter.go -./eth/filters/filter_system.go -./eth/gasprice/gasprice.go -./eth/metrics.go -./eth/protocol.go -./ethstats/ethstats.go -./eth/tracers/internal/tracers/tracers.go -./eth/tracers/tracer.go -./eth/tracers/tracers.go -./internal/debug/api.go -./internal/debug/flags.go -./internal/debug/loudpanic_fallback.go -./internal/debug/loudpanic.go -./internal/debug/trace_fallback.go -./internal/debug/trace.go -./internal/ethapi/addrlock.go -./miner/unconfirmed.go -./node/defaults.go -./node/errors.go -./params/config.go -./params/dao.go -./params/denomination.go -./params/network_params.go -./params/version.go -./rpc/constants_unix_nocgo.go -./rpc/doc.go -./rpc/errors.go -./rpc/gzip.go -./rpc/handler.go -./rpc/http.go -./rpc/ipc_js.go -./rpc/json.go -./rpc/server.go -./rpc/service.go -./rpc/subscription.go -./rpc/websocket.go -./accounts/* diff --git a/hacked-list.txt b/hacked-list.txt deleted file mode 100644 index 3182b56..0000000 --- a/hacked-list.txt +++ /dev/null @@ -1,43 +0,0 @@ -./consensus/dummy/consensus.go -./consensus/clique/clique.go -./consensus/consensus.go -./consensus/ethash/consensus.go -./core/blockchain.go -./core/events.go -./core/evm.go -./core/genesis.go -./core/gen_genesis_account.go -./core/gen_genesis.go -./core/rawdb/accessors_chain.go -./core/state/journal.go -./core/state_processor.go -./core/state/statedb.go -./core/state/state_object.go -./core/tx_pool.go -./core/types/block.go -./core/vm/errors.go -./core/vm/evm.go -./core/vm/instructions.go -./core/vm/interface.go -./core/vm/interpreter.go -./core/vm/jump_table.go -./core/vm/memory_table.go -./core/vm/opcodes.go -./eth/api_backend.go -./eth/api.go -./eth/api_tracer.go -./eth/backend.go -./eth/config.go -./eth/gen_config.go -./eth/tracers/internal/tracers/assets.go -./internal/ethapi/api.go -./internal/ethapi/backend.go -./miner/miner.go -./miner/worker.go -./node/api.go -./node/config.go -./node/node.go -./node/service.go -./params/protocol_params.go -./rpc/client.go -./rpc/types.go diff --git a/notes/copied-list.txt b/notes/copied-list.txt new file mode 100644 index 0000000..94353ff --- /dev/null +++ b/notes/copied-list.txt @@ -0,0 +1,107 @@ +./consensus/clique/api.go +./consensus/clique/snapshot.go +./consensus/errors.go +./consensus/ethash/algorithm.go +./consensus/ethash/api.go +./consensus/ethash/ethash.go +./consensus/ethash/sealer.go +./consensus/misc/dao.go +./consensus/misc/forks.go +./core/blockchain_insert.go +./core/blocks.go +./core/block_validator.go +./core/bloombits/doc.go +./core/bloombits/generator.go +./core/bloombits/matcher.go +./core/bloombits/scheduler.go +./core/chain_indexer.go +./core/error.go +./core/gaspool.go +./core/genesis_alloc.go +./core/headerchain.go +./core/mkalloc.go +./core/rawdb/accessors_indexes.go +./core/rawdb/accessors_metadata.go +./core/rawdb/database.go +./core/rawdb/freezer.go +./core/rawdb/freezer_reinit.go +./core/rawdb/freezer_table.go +./core/rawdb/schema.go +./core/rawdb/table.go +./core/state/database.go +./core/state/dump.go +./core/state/iterator.go +./core/state_prefetcher.go +./core/state/sync.go +./core/state_transition.go +./core/tx_cacher.go +./core/tx_journal.go +./core/tx_list.go +./core/tx_noncer.go +./core/types/bloom9.go +./core/types/derive_sha.go +./core/types/gen_header_json.go +./core/types/gen_log_json.go +./core/types/gen_receipt_json.go +./core/types/gen_tx_json.go +./core/types.go +./core/types/log.go +./core/types/receipt.go +./core/types/transaction.go +./core/types/transaction_signing.go +./core/vm/analysis.go +./core/vm/common.go +./core/vm/contract.go +./core/vm/contracts.go +./core/vm/doc.go +./core/vm/eips.go +./core/vm/gas.go +./core/vm/gas_table.go +./core/vm/gen_structlog.go +./core/vm/intpool.go +./core/vm/int_pool_verifier_empty.go +./core/vm/int_pool_verifier.go +./core/vm/logger.go +./core/vm/logger_json.go +./core/vm/memory.go +./core/vm/stack.go +./core/vm/stack_table.go +./eth/bloombits.go +./eth/filters/api.go +./eth/filters/filter.go +./eth/filters/filter_system.go +./eth/gasprice/gasprice.go +./eth/metrics.go +./eth/protocol.go +./ethstats/ethstats.go +./eth/tracers/internal/tracers/tracers.go +./eth/tracers/tracer.go +./eth/tracers/tracers.go +./internal/debug/api.go +./internal/debug/flags.go +./internal/debug/loudpanic_fallback.go +./internal/debug/loudpanic.go +./internal/debug/trace_fallback.go +./internal/debug/trace.go +./internal/ethapi/addrlock.go +./miner/unconfirmed.go +./node/defaults.go +./node/errors.go +./params/config.go +./params/dao.go +./params/denomination.go +./params/network_params.go +./params/version.go +./rpc/constants_unix_nocgo.go +./rpc/doc.go +./rpc/errors.go +./rpc/gzip.go +./rpc/handler.go +./rpc/http.go +./rpc/ipc_js.go +./rpc/json.go +./rpc/server.go +./rpc/service.go +./rpc/subscription.go +./rpc/websocket.go +./accounts/* diff --git a/notes/hacked-list.txt b/notes/hacked-list.txt new file mode 100644 index 0000000..3182b56 --- /dev/null +++ b/notes/hacked-list.txt @@ -0,0 +1,43 @@ +./consensus/dummy/consensus.go +./consensus/clique/clique.go +./consensus/consensus.go +./consensus/ethash/consensus.go +./core/blockchain.go +./core/events.go +./core/evm.go +./core/genesis.go +./core/gen_genesis_account.go +./core/gen_genesis.go +./core/rawdb/accessors_chain.go +./core/state/journal.go +./core/state_processor.go +./core/state/statedb.go +./core/state/state_object.go +./core/tx_pool.go +./core/types/block.go +./core/vm/errors.go +./core/vm/evm.go +./core/vm/instructions.go +./core/vm/interface.go +./core/vm/interpreter.go +./core/vm/jump_table.go +./core/vm/memory_table.go +./core/vm/opcodes.go +./eth/api_backend.go +./eth/api.go +./eth/api_tracer.go +./eth/backend.go +./eth/config.go +./eth/gen_config.go +./eth/tracers/internal/tracers/assets.go +./internal/ethapi/api.go +./internal/ethapi/backend.go +./miner/miner.go +./miner/worker.go +./node/api.go +./node/config.go +./node/node.go +./node/service.go +./params/protocol_params.go +./rpc/client.go +./rpc/types.go -- cgit v1.2.3-70-g09d2 From 99a0be028ab8df4bc6028f9a105e131a8984a599 Mon Sep 17 00:00:00 2001 From: Aaron Buchwald Date: Sun, 20 Sep 2020 15:25:50 -0400 Subject: Treat requests for pending block as requests for accepted block --- eth/api_backend.go | 28 ++++++++++-------- eth/gasprice/gasprice.go | 72 +---------------------------------------------- params/protocol_params.go | 4 +++ plugin/evm/block.go | 3 +- plugin/evm/vm.go | 10 ++----- 5 files changed, 26 insertions(+), 91 deletions(-) diff --git a/eth/api_backend.go b/eth/api_backend.go index bbc8691..6c5ebd8 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -65,10 +65,12 @@ func (b *EthAPIBackend) SetHead(number uint64) { } func (b *EthAPIBackend) HeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Header, error) { - // Pending block is only known by the miner + // Pending block is only known by the miner in + // Ethereum, but Coreth does not have the same notion. + // So we treat requests for the pending block identically + // to the latest accepted block instead if number == rpc.PendingBlockNumber { - block := b.eth.miner.PendingBlock() - return block.Header(), nil + return b.eth.AcceptedBlock().Header(), nil } // Otherwise resolve and return the block if number == rpc.LatestBlockNumber { @@ -102,10 +104,12 @@ func (b *EthAPIBackend) HeaderByHash(ctx context.Context, hash common.Hash) (*ty } func (b *EthAPIBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error) { - // Pending block is only known by the miner + // Pending block is only known by the miner in + // Ethereum, but Coreth does not have the same notion. + // So we treat requests for the pending block identically + // to the latest accepted block instead if number == rpc.PendingBlockNumber { - block := b.eth.miner.PendingBlock() - return block, nil + return b.eth.AcceptedBlock(), nil } // Otherwise resolve and return the block if number == rpc.LatestBlockNumber { @@ -143,12 +147,12 @@ func (b *EthAPIBackend) BlockByNumberOrHash(ctx context.Context, blockNrOrHash r } func (b *EthAPIBackend) StateAndHeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*state.StateDB, *types.Header, error) { - // Pending state is only known by the miner - if number == rpc.PendingBlockNumber { - block, state := b.eth.miner.Pending() - return state, block.Header(), nil - } - // Otherwise resolve the block number and return its state + // Note: Ethereum typically first checks if the request is for + // the pending block (by rpc.PendingBlockNumber), but Coreth + // does not have the same notion of the miner having a pending + // block, so this is skipped here + + // Request the block by its number and retrieve its state header, err := b.HeaderByNumber(ctx, number) if err != nil { return nil, nil, err diff --git a/eth/gasprice/gasprice.go b/eth/gasprice/gasprice.go index 14f50b1..14476ab 100644 --- a/eth/gasprice/gasprice.go +++ b/eth/gasprice/gasprice.go @@ -95,77 +95,7 @@ func NewOracle(backend OracleBackend, params Config) *Oracle { // SuggestPrice returns a gasprice so that newly created transaction can // have a very high chance to be included in the following blocks. func (gpo *Oracle) SuggestPrice(ctx context.Context) (*big.Int, error) { - head, _ := gpo.backend.HeaderByNumber(ctx, rpc.LatestBlockNumber) - headHash := head.Hash() - - // If the latest gasprice is still available, return it. - gpo.cacheLock.RLock() - lastHead, lastPrice := gpo.lastHead, gpo.lastPrice - gpo.cacheLock.RUnlock() - if headHash == lastHead { - return lastPrice, nil - } - gpo.fetchLock.Lock() - defer gpo.fetchLock.Unlock() - - // Try checking the cache again, maybe the last fetch fetched what we need - gpo.cacheLock.RLock() - lastHead, lastPrice = gpo.lastHead, gpo.lastPrice - gpo.cacheLock.RUnlock() - if headHash == lastHead { - return lastPrice, nil - } - var ( - sent, exp int - number = head.Number.Uint64() - result = make(chan getBlockPricesResult, gpo.checkBlocks) - quit = make(chan struct{}) - txPrices []*big.Int - ) - for sent < gpo.checkBlocks && number > 0 { - go gpo.getBlockPrices(ctx, types.MakeSigner(gpo.backend.ChainConfig(), big.NewInt(int64(number))), number, sampleNumber, result, quit) - sent++ - exp++ - number-- - } - for exp > 0 { - res := <-result - if res.err != nil { - close(quit) - return lastPrice, res.err - } - exp-- - // Nothing returned. There are two special cases here: - // - The block is empty - // - All the transactions included are sent by the miner itself. - // In these cases, use the latest calculated price for samping. - if len(res.prices) == 0 { - res.prices = []*big.Int{lastPrice} - } - // Besides, in order to collect enough data for sampling, if nothing - // meaningful returned, try to query more blocks. But the maximum - // is 2*checkBlocks. - if len(res.prices) == 1 && len(txPrices)+1+exp < gpo.checkBlocks*2 && number > 0 { - go gpo.getBlockPrices(ctx, types.MakeSigner(gpo.backend.ChainConfig(), big.NewInt(int64(number))), number, sampleNumber, result, quit) - sent++ - exp++ - number-- - } - txPrices = append(txPrices, res.prices...) - } - price := lastPrice - if len(txPrices) > 0 { - sort.Sort(bigIntArray(txPrices)) - price = txPrices[(len(txPrices)-1)*gpo.percentile/100] - } - if price.Cmp(gpo.maxPrice) > 0 { - price = new(big.Int).Set(gpo.maxPrice) - } - gpo.cacheLock.Lock() - gpo.lastHead = headHash - gpo.lastPrice = price - gpo.cacheLock.Unlock() - return price, nil + return params.MinGasPrice, nil } type getBlockPricesResult struct { diff --git a/params/protocol_params.go b/params/protocol_params.go index cbd036b..3536c83 100644 --- a/params/protocol_params.go +++ b/params/protocol_params.go @@ -150,4 +150,8 @@ var ( GenesisDifficulty = big.NewInt(131072) // Difficulty of the Genesis block. MinimumDifficulty = big.NewInt(131072) // The minimum that the difficulty may ever be. DurationLimit = big.NewInt(13) // The decision boundary on the blocktime duration used to determine whether difficulty should go up or not. + + // MinGasPrice is the number of nAVAX required per gas unit for a transaction + // to be valid, measured in wei + MinGasPrice = big.NewInt(470 * GWei) ) diff --git a/plugin/evm/block.go b/plugin/evm/block.go index 1e1d710..ee5b7c6 100644 --- a/plugin/evm/block.go +++ b/plugin/evm/block.go @@ -8,6 +8,7 @@ import ( "fmt" "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" @@ -80,7 +81,7 @@ func (b *Block) Verify() error { if b.vm.ctx.IsBootstrapped() { // Ensure the minimum gas price is paid for every transaction for _, tx := range b.ethBlock.Transactions() { - if tx.GasPrice().Cmp(minGasPrice) < 0 { + if tx.GasPrice().Cmp(params.MinGasPrice) < 0 { return errInvalidBlock } } diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index 13d4d3f..2c6dc1a 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -87,10 +87,6 @@ const ( ) var ( - // minGasPrice is the number of nAVAX required per gas unit for a transaction - // to be valid, measured in wei - minGasPrice = big.NewInt(470 * params.GWei) - txFee = units.MilliAvax errEmptyBlock = errors.New("empty block") @@ -258,10 +254,10 @@ func (vm *VM) Initialize( // 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 = minGasPrice + config.Miner.GasPrice = params.MinGasPrice config.RPCTxFeeCap = 100 // 100 AVAX - config.GPO.Default = minGasPrice - config.TxPool.PriceLimit = minGasPrice.Uint64() + config.GPO.Default = params.MinGasPrice + config.TxPool.PriceLimit = params.MinGasPrice.Uint64() config.TxPool.NoLocals = true if err := config.SetGCMode("archive"); err != nil { -- cgit v1.2.3-70-g09d2