Commit Graph

300 Commits

Author SHA1 Message Date
setunapo
139eb3f467 worker: fix a bug of the delay timer.
`fillTransactions` will call `commitTransactions` twice, if the delay
timer is expired during the first call, it will make the delay timer
never be triggered in the second commitTransactions call.
Pseudo code:
    x := time.NewTimer(time.Second)
    <-x.C
    fmt.Println("read delay 1")
    <-x.C
    fmt.Println("read delay 2")  // will never hit
2022-11-17 11:42:03 +08:00
setunapo
0789afe6e7 worker: remove pre-seal empty block
pre-seal empty block is for PoW to deliver an empty block ASAP to
gain the block mine reward.

It is useless for PoS consensus and it does not work for BSC either.

Delete the code to make worker simpler.
2022-11-16 17:57:44 +08:00
setunapo
086a99b407 worker: no need to add more transaction if not mining
It could be a very old PoW logic, which try to add more transaction
into the pending block when mining is stopped.
Mining can be stopped when:
  1.download started.
  2.manually stopped by RPC.
It is unnecessary to add more transaction into the pending block if a validator is stopped.
And updateSnapshot() is not needed as well, it is to get the pending mining snapshot.
2022-11-16 10:47:58 +08:00
setunapo
fe1c8622f6 parlia: Delay() with DelayLeftOver
Right now, DelayLeftOver is used to reserve time for block finalize, not block
broadcast. And the code does not work as expected.

The general block generation could be described as:
|- fillTransactions -|- finalize a block -|- wait until the period(3s) reached -|- broadcast -|
2022-11-16 10:47:58 +08:00
setunapo
d1ed977d89 worker: change interrupt type from *int to chan
channel operation is preferred than atomic value check in golang.
And it will help for the further refactor on worker.
2022-11-15 13:26:11 +08:00
setunapo
b4dcff5772 worker: remove the code of resubmit interval adjust
resubmit intervalAdjust is for PoW only, to remove it to make worker simpler.

With PoW, there will be a periodic timer to check if it is the time to stop
packing transaction and start calculating the desired hash value, since other miner
could succeed in hash compute if it spends too much time packing transactions.
It will commit the current fruit to calculate root at a reasonable time.
And it will schedule a new work to get a big block if new transaction was received.

When there are too many transactions in the TxPool, the interval of the resubmit timer would be
increased and vice versa.

But it is not needed with PoS related consensus, since the block interval is determined in PoS,
and there is already a timer to stop too long packing.
2022-11-15 13:26:11 +08:00
Leon
01b78d4789
miner: disable enforceTip when get txs from txpool (#1166) 2022-11-07 10:42:05 +08:00
zjubfd
4e2f5c6263 merge with master branch 2022-10-31 15:12:21 +08:00
Jolly Zhao
c46671df97 parlia: the newChainHead mights not be imported to Pralia.Snapshot ASAP 2022-10-28 11:42:06 +08:00
rjl493456442
aedd5aaba1 eth, miner: retrieve mining state from live database (#25139)
* miner: retrieve mining state from live database

* eth/catalyst: ignore stale fcu events from cl
2022-10-21 14:01:52 +08:00
setunapo
77c8372cc4 Trie prefetch on state pretch (#996)
* feature: do trie prefetch on state prefetch

Currently, state prefetch just pre execute the transactions and discard the results.
It is helpful to increase the snapshot cache hit rate.
It would be more helpful, if it can do trie prefetch at the same time, since the it will
preload the trie node and build the trie tree in advance.
This patch is to implement it, by reusing the main trie prefetch and doing finalize after
transaction is executed.

* some code improvements for trie prefetch

** increase pendingSize before dispatch tasks
** use throwaway StateDB for TriePrefetchInAdvance and remove the prefetcherLock
** remove the necessary drain operation in trie prefetch mainloop,
   trie prefetcher won't be used after close.
2022-08-01 17:41:50 +08:00
kyrie-yl
51bfecacb0 broadcast block before commit block and add metrics (#975)
Signed-off-by: cryyl <yl.on.the.way@gmail.com>
2022-08-01 17:41:50 +08:00
dylanhuang
403b19c629
[R4R] fix: Incorrect merkle root issue when enabling pipecommit with miner (#1011)
[R4R] fix: Incorrect merkle root issue when enabling pipecommit with miner (#1011)
2022-07-22 15:58:06 +08:00
dylanhuang
21c4ecee3e
fix: incorrect behavior of miner (#1007) 2022-07-20 17:33:51 +08:00
dylanhuang
fd1d1e356e
fix: nil pointer issue when stopping mining new block (#983) 2022-07-08 13:17:40 +08:00
j75689
79bd42836c fix: code compatibility fixes 2022-07-05 11:14:21 +08:00
zjubfd
a50a05d624 merge with go-ethereum 1.1.5 2022-02-10 18:48:16 +08:00
rjl493456442
2d20fed893
miner: avoid data race in miner (#24349) 2022-02-07 18:34:13 +01:00
rjl493456442
78636ee568
eth, miner: use miner for post-merge block production (#23256)
* eth, miner: remove duplicated code

* eth/catalyst: remove unneeded code

* miner: keep update pending state even the Merge is happened

* eth, miner: rebase

* miner: fix tests

* eth, miner: address comments from marius

* miner: use empty zero randomness for pending blocks after the merge

* eth/catalyst: gofmt

* miner: add warning log for state recovery

* miner: ignore uncles for post-merge blocks

Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2022-01-24 09:19:52 +02:00
rjl493456442
7f7877a023
miner: update pending block even after the PoS transition (#24075) 2021-12-07 10:42:09 +01:00
Marius van der Wijden
93f196c4b0
eth/catalyst: implement kintsugi spec v1.0.0-alpha.4 (#23984)
This PR implements the new kintsugi specification which can be found here: https://github.com/ethereum/execution-apis/blob/v1.0.0-alpha.4/src/engine/specification.md
2021-12-03 16:26:28 +01:00
Marius van der Wijden
3038e480f5
all: core rework for the merge transition (#23761)
* all: work for eth1/2 transtition

* consensus/beacon, eth: change beacon difficulty to 0

* eth: updates

* all: add terminalBlockDifficulty config, fix rebasing issues

* eth: implemented merge interop spec

* internal/ethapi: update to v1.0.0.alpha.2

                                                                 This commit updates the code to the new spec, moving payloadId into
                                                                 it's own object. It also fixes an issue with finalizing an empty blockhash.
                                                                 It also properly sets the basefee

* all: sync polishes, other fixes + refactors

* core, eth: correct semantics for LeavePoW, EnterPoS

* core: fixed rebasing artifacts

* core: light: performance improvements

* core: use keyed field (f)

* core: eth: fix compilation issues + tests

* eth/catalyst: dbetter error codes

* all: move Merger to consensus/, remove reliance on it in bc

* all: renamed EnterPoS and LeavePoW to ReachTDD and FinalizePoS

* core: make mergelogs a function

* core: use InsertChain instead of InsertBlock

* les: drop merger from lightchain object

* consensus: add merger

* core: recoverAncestors in catalyst mode

* core: fix nitpick

* all: removed merger from beacon, use TTD, nitpicks

* consensus: eth: add docstring, removed unnecessary code duplication

* consensus/beacon: better comment

* all: easy to fix nitpicks by karalabe

* consensus/beacon: verify known headers to be sure

* core: comments

* core: eth: don't drop peers who advertise blocks, nitpicks

* core: never add beacon blocks to the future queue

* core: fixed nitpicks

* consensus/beacon: simplify IsTTDReached check

* consensus/beacon: correct IsTTDReached check

Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2021-11-26 13:23:02 +02:00
Martin Holst Swende
476fb565ce
miner, consensus/clique: avoid memory leak during block stasis (#23861)
This PR fixes a problem which arises on clique networks when there is a network stall. Previously, the worker packages were tracked, even if the sealing engine decided not to seal the block (due to clique rules about recent signing). These tracked-but-not-sealed blocks kept building up in memory. 
This PR changes the situation so the sealing engine instead returns an error, and the worker can thus un-track the package.
2021-11-05 16:17:13 +01:00
Lee Bousfield
c113520d5d
miner: fix receipt deep copy in worker (#23835) 2021-11-01 07:50:29 +01:00
jwasinger
011fe3eb5e
core: remove unused error from TxPool.Pending (#23720) 2021-10-13 23:00:45 +02:00
Marius van der Wijden
ee120ef865
miner: fix data race during shutdown (#23435)
This fixes a data race on worker.current by moving the call to StopPrefetcher
into the main loop.

The commit also contains fixes for two other races in unit tests of unrelated packages.
2021-10-08 20:12:52 +02:00
Martin Holst Swende
28d30b51f8
eth: close miner on exit (instead of just stopping) (#21992)
This ensures that all miner goroutines have exited before stopping the blockchain. 

Co-authored-by: Felix Lange <fjl@twurst.com>
2021-10-08 18:36:58 +02:00
gary rong
6d175460df
cmd, core, eth, miner: deprecate miner.gastarget flag (#23213) 2021-08-10 11:28:33 +03:00
Péter Szilágyi
dea71556cc
eth/gasprice, internal/ethapi, miner: minor feehistory fixes 2021-07-08 21:50:35 +03:00
Martin Holst Swende
d21a069619
eth, miner: add RPC method to modify miner gaslimit (pre london: ceiling) (#23134) 2021-07-06 10:35:39 +02:00
Marius van der Wijden
686b2884ee
all: removed blockhash from statedb (#23126)
This PR removes the blockhash from the statedb
2021-06-30 15:17:01 +02:00
Felföldi Zsolt
35dbf7a8a3
eth/gasprice: implement feeHistory API (#23033)
* eth/gasprice: implement feeHistory API

* eth/gasprice: factored out resolveBlockRange

* eth/gasprice: add sanity check for missing block

* eth/gasprice: fetch actual gas used from receipts

* miner, eth/gasprice: add PendingBlockAndReceipts

* internal/ethapi: use hexutil.Big

* eth/gasprice: return error when requesting beyond head block

* eth/gasprice: fixed tests and return errors correctly

* eth/gasprice: rename receiver name

* eth/gasprice: return directly if blockCount == 0

Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
2021-06-28 16:16:32 +02:00
Péter Szilágyi
c503f98f6d
all: rename internal 1559 gas fields, add support for graphql (#23010)
* all: rename internal 1559 gas fields, add support for graphql

* cmd/evm/testdata, core: use public 1559 gas names on API surfaces
2021-06-08 12:05:41 +02:00
Péter Szilágyi
7e915ee379
core, eth, miner: enforce configured mining reward post 1559 too 2021-06-04 10:18:37 +03:00
Martin Holst Swende
a6c462781f
EIP-1559: miner changes (#22896)
* core/types, miner: create TxWithMinerFee wrapper, add EIP-1559 support to TransactionsByMinerFeeAndNonce

miner: set base fee when creating a new header, handle gas limit, log miner fees

* all: rename to NewTransactionsByPriceAndNonce

* core/types, miner: rename to NewTransactionsByPriceAndNonce + EffectiveTip

miner: activate 1559 for testGenerateBlockAndImport tests

* core,miner: revert naming to TransactionsByPriceAndTime

* core/types/transaction: update effective tip calculation logic

* miner: update aleut to london

* core/types/transaction_test: use correct signer for 1559 txs + add back sender check

* miner/worker: calculate gas target from gas limit

* core, miner: fix block  gas limits for 1559

Co-authored-by: Ansgar Dietrichs <adietrichs@gmail.com>
Co-authored-by: lightclient@protonmail.com <lightclient@protonmail.com>
2021-05-21 09:59:26 +02:00
yutianwu
061cd5030c upgrade to 1.10.2 2021-04-16 12:45:26 +08:00
zjubfd
f8faf7faaa
[R4R]apply max commit tx time for miner worker (#112)
* apply max commit tx time for miner worker

* update to 200 ms
2021-03-19 13:23:44 +08:00
lightclient
bbfb1e4008
all: add support for EIP-2718, EIP-2930 transactions (#21502)
This adds support for EIP-2718 typed transactions as well as EIP-2930
access list transactions (tx type 1). These EIPs are scheduled for the
Berlin fork.

There very few changes to existing APIs in core/types, and several new APIs
to deal with access list transactions. In particular, there are two new
constructor functions for transactions: types.NewTx and types.SignNewTx.
Since the canonical encoding of typed transactions is not RLP-compatible,
Transaction now has new methods for encoding and decoding: MarshalBinary
and UnmarshalBinary.

The existing EIP-155 signer does not support the new transaction types.
All code dealing with transaction signatures should be updated to use the
newer EIP-2930 signer. To make this easier for future updates, we have
added new constructor functions for types.Signer: types.LatestSigner and
types.LatestSignerForChainID. 

This change also adds support for the YoloV3 testnet.

Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Felix Lange <fjl@twurst.com>
Co-authored-by: Ryan Schneider <ryanleeschneider@gmail.com>
2021-02-25 15:26:57 +01:00
ucwong
83e4c49e2b
trie : use trie.NewStackTrie instead of new(trie.Trie) (#22246)
The PR makes use of the stacktrie, which is is more lenient on resource consumption, than the regular trie, in cases where we only need it for DeriveSha
2021-02-02 13:09:23 +01:00
Péter Szilágyi
42f9f1f073
core/state: convert prefetcher to concurrent per-trie loader 2021-01-21 01:47:14 +02:00
Martin Holst Swende
9584f56b9d
miner: avoid sleeping in miner (#22108)
This PR removes a logic in the miner, which was originally intended to help temporary testnets based on ethash from "running off into the future". If the difficulty was low, and a few computers started mining several blocks per second, the ethash rules (which demand 1s delay between blocks) would push the blocktimes further and further away.
The solution was to make the miner sleep while this happened.

Nowadays, this problem is solved instead by PoA chains, and it's recommended to let testnets and devnets be based on clique instead. The existing logic is problematic, since it can cause stalls within the miner making it difficult for remote workers to submit work if the channel is blocked on a sleep.

Credits to Saar Tochner for reporting this via the bug bounty
2021-01-05 10:44:33 +01:00
lzhfromustc
62dc59c2bd
miner, test: fix potential goroutine leak (#21989)
In miner/worker.go, there are two goroutine using channel w.newWorkCh: newWorkerLoop() sends to this channel, and mainLoop() receives from this channel. Only the receive operation is in a select.

However, w.exitCh may be closed by another goroutine. This is fine for the receive since receive is in select, but if the send operation is blocking, then it will block forever. This commit puts the send in a select, so it won't block even if w.exitCh is closed.

Similarly, there are two goroutines using channel errc: the parent that runs the test receives from it, and the child created at line 573 sends to it. If the parent goroutine exits too early by calling t.Fatalf() at line 614, then the child goroutine will be blocked at line 574 forever. This commit adds 1 buffer to errc. Now send will not block, and receive is not influenced because receive still needs to wait for the send.
2020-12-11 10:29:42 +01:00
Martin Holst Swende
7770e41cb5
core: improve contextual information on core errors (#21869)
A lot of times when we hit 'core' errors, example: invalid tx, the information provided is
insufficient. We miss several pieces of information: what account has nonce too high,
and what transaction in that block was offending?

This PR adds that information, using the new type of wrapped errors.
It also adds a testcase which (partly) verifies the output from the errors.

The first commit changes all usage of direct equality-checks on core errors, into
using errors.Is. The second commit adds contextual information. This wraps most
of the core errors with more information, and also wraps it one more time in
stateprocessor, to further provide tx index and tx hash, if such a tx is encoutered in
a block. The third commit uses the chainmaker to try to generate chains with such
errors in them, thus triggering the errors and checking that the generated string meets
expectations.
2020-12-04 12:22:19 +01:00
Marius van der Wijden
7cf56d6f06
miner: use channels instead of atomics in update loop (#21536)
This PR changes several different things:

- Adds test cases for the miner loop
- Stops the worker if it wasn't already stopped in worker.Close()
- Uses channels instead of atomics in the miner.update() loop

Co-authored-by: Felix Lange <fjl@twurst.com>
2020-09-10 19:27:42 +02:00
gary rong
87c0ba9213
core, eth, les, trie: add a prefix to contract code (#21080) 2020-08-21 15:10:40 +03:00
HaoyangLiu
650d066757 resolve comment 2020-08-07 17:16:39 +08:00
HaoyangLiu
3789ea31dd improve upgrade config 2020-08-07 17:15:09 +08:00
HaoyangLiu
3f36e996df framework for upgrade system contract 2020-08-07 17:15:09 +08:00
Robert Zaremba
37564ceda6
miner: refactor helper functions in worker.go (#21044)
This reduces complexity of some lengthy functions in worker.go,
making the code easier to read.
2020-07-28 18:16:49 +02:00
fudongbai
4bd4469151
add gas limit check in parlia implement 2020-06-18 00:26:27 +08:00