erigon-pulse/consensus
Manav Darji 1da4d3abbf
eth, consensus/bor: fixes and improvements related to mining (#6051)
In context of https://github.com/ledgerwatch/erigon/issues/5694, this PR
adds some fixes and improvement in the mining flow. Also, a relevant
change in txpool (present in erigon-lib) is made here:
https://github.com/ledgerwatch/erigon-lib/pull/737

#### Changes in triggering mining in `startMining()`
The mining module didn't honour the block time as a simple 3 second
timer and a notifier from txpool was used to trigger mining. This would
cause inconsistencies, at least with the bor consensus. Hence, a geth
like approach is used instead for simplicity. A new head channel
subscription is added in the `startMining()` loop which would notify the
addition of new block. Hence, this would make sure that the block time
is being honoured. Moreover, the fixed 3 second timer is replaced by the
`miner.recommit` value set using flags.

####  Changes in the arrangement of calls made post mining
When all the mining stages are completed, erigon writes all the data in
a cache. It then processes the block through all the stages as it would
process a block received from P2P. In this case, some of the stages
aren't really required. Like the block header and body download stage is
not required as the block was mined locally. Even execution stage is not
required as it already went through it in the mining stages.

Now, we encountered an issue where the chain was halted and kept mining
the same block again and again (liveness issue). The root cause is
because of an error in a stage of it's parent block. This stage turns
out to be the 4th stage which is "Block body download" stage. This stage
tries to download the block body from peers using the headers. As, we
mined this block locally we don't really need to download anything (or
process anything again). Hence, it reaches out to the cache which we
store for the block body.

Interestingly that cache turned out to be empty for some blocks. This
was because post mining, before adding block header and body to a cache,
we call the broadcast method which starts the staged sync. So,
technically it’s a bit uncertain at any stage if the block header and
body has been written or not.(see
[this](https://github.com/ledgerwatch/erigon/blob/devel/eth/backend.go#L553-L572)).
To achieve complete certainty, we rearranged the calls with the write to
cache being called first and broadcast next. This pretty much solves the
issue as now we’re sure that we’d always have a block body in the cache
when we reach the body download stage.

#### Misc changes
This PR also adds some logs in bor consensus.
2022-11-18 02:39:16 +03:00
..
aura Fix panic("durations cannot be empty") (#6029) 2022-11-11 15:24:58 +01:00
bor eth, consensus/bor: fixes and improvements related to mining (#6051) 2022-11-18 02:39:16 +03:00
clique Rewrite bytecode of the token contract on Gnosis Chain (#5997) 2022-11-08 13:03:06 +01:00
db Create in-memory MDBX inside dirs.Tmp (#5702) 2022-10-11 16:49:38 +01:00
ethash Rewrite bytecode of the token contract on Gnosis Chain (#5997) 2022-11-08 13:03:06 +01:00
misc Fix Gnosis Chain fork ID (#5487) 2022-09-23 12:26:35 +02:00
parlia Rewrite bytecode of the token contract on Gnosis Chain (#5997) 2022-11-08 13:03:06 +01:00
serenity Rewrite bytecode of the token contract on Gnosis Chain (#5997) 2022-11-08 13:03:06 +01:00
consensus.go Rewrite bytecode of the token contract on Gnosis Chain (#5997) 2022-11-08 13:03:06 +01:00
errors.go Serenity engine: fall back to eth1 engine before the Merge (#3112) 2021-12-13 18:29:38 +01:00
result.go Clean up DEBUG category logs (#2776) 2021-10-05 08:14:04 +07:00