From 06515671a63074d982ff90cd7a35deb3de5ffa1f Mon Sep 17 00:00:00 2001 From: egonspace Date: Mon, 24 Jun 2024 11:55:46 +0900 Subject: [PATCH] feat: update snapshot pending state --- ethclient/gethclient/gethclient_test.go | 2 +- internal/ethapi/api.go | 4 ++-- miner/worker.go | 12 +++++++++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/ethclient/gethclient/gethclient_test.go b/ethclient/gethclient/gethclient_test.go index 718dc14bbcb6..bbae8973b422 100644 --- a/ethclient/gethclient/gethclient_test.go +++ b/ethclient/gethclient/gethclient_test.go @@ -147,7 +147,7 @@ func testAccessList(t *testing.T, client *rpc.Client) { From: testAddr, To: &common.Address{}, Gas: 21000, - GasPrice: big.NewInt(765625000), + GasPrice: big.NewInt(875000000), Value: big.NewInt(1), } al, gas, vmErr, err := ec.CreateAccessList(context.Background(), msg) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 08d85442cc50..ceab2e801706 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1338,7 +1338,7 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr // EstimateGas returns an estimate of the amount of gas needed to execute the // given transaction against the current pending block. func (s *PublicBlockChainAPI) EstimateGas(ctx context.Context, args TransactionArgs, blockNrOrHash *rpc.BlockNumberOrHash) (hexutil.Uint64, error) { - bNrOrHash := rpc.BlockNumberOrHashWithNumber(rpc.PendingBlockNumber) + bNrOrHash := rpc.BlockNumberOrHashWithNumber(rpc.LatestBlockNumber) if blockNrOrHash != nil { bNrOrHash = *blockNrOrHash } @@ -1622,7 +1622,7 @@ type accessListResult struct { // CreateAccessList creates a EIP-2930 type AccessList for the given transaction. // Reexec and BlockNrOrHash can be specified to create the accessList on top of a certain state. func (s *PublicBlockChainAPI) CreateAccessList(ctx context.Context, args TransactionArgs, blockNrOrHash *rpc.BlockNumberOrHash) (*accessListResult, error) { - bNrOrHash := rpc.BlockNumberOrHashWithNumber(rpc.PendingBlockNumber) + bNrOrHash := rpc.BlockNumberOrHashWithNumber(rpc.LatestBlockNumber) if blockNrOrHash != nil { bNrOrHash = *blockNrOrHash } diff --git a/miner/worker.go b/miner/worker.go index c30d38ed10ed..364bf034970f 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -119,6 +119,7 @@ func (env *environment) copy() *environment { coinbase: env.coinbase, header: types.CopyHeader(env.header), receipts: copyReceipts(env.receipts), + till: env.till, } if env.gasPool != nil { gasPool := *env.gasPool @@ -535,7 +536,7 @@ func (w *worker) newWorkLoopEx(recommit time.Duration) { // commitSimple just starts a new commitNewWork commitSimple := func() { - if atomic.CompareAndSwapInt32(&busyMining, 0, 1) { + if wemixminer.AmPartner() && atomic.CompareAndSwapInt32(&busyMining, 0, 1) { w.newWorkCh <- &newWorkReq{interrupt: nil, noempty: false, timestamp: time.Now().Unix()} atomic.StoreInt32(&w.newTxs, 0) atomic.StoreInt32(&busyMining, 0) @@ -1268,8 +1269,6 @@ func (w *worker) commitTransactionsEx(env *environment, interrupt *int32, tstart } - time.Sleep(time.Until(*env.till)) - log.Debug("Block", "number", env.header.Number.Int64(), "elapsed", common.PrettyDuration(time.Since(tstart)), "txs", len(committedTxs)) return false @@ -1769,6 +1768,13 @@ func (w *worker) commitEx(env *environment, interval func(), update bool, start } logs = append(logs, receipt.Logs...) } + + if update { + w.updateSnapshot(env) + update = false + } + time.Sleep(time.Until(*env.till)) + if !wemixminer.IsPoW() { if err = wemixminer.ReleaseMiningToken(sealedBlock.Number(), sealedBlock.Hash(), sealedBlock.ParentHash()); err != nil { return err