Skip to content

Commit

Permalink
feat: update snapshot pending state
Browse files Browse the repository at this point in the history
  • Loading branch information
egonspace committed Jun 24, 2024
1 parent 8cfed0d commit 0651567
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ethclient/gethclient/gethclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
12 changes: 9 additions & 3 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0651567

Please sign in to comment.