mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 23:26:44 +00:00
Revert "miner :: add : check to run worker commitWork (#828)"
This reverts commit 6dee9b5f40.
This commit is contained in:
parent
73821b46c9
commit
d25732c949
2 changed files with 66 additions and 97 deletions
|
|
@ -599,9 +599,7 @@ func (w *worker) mainLoop(ctx context.Context) {
|
||||||
select {
|
select {
|
||||||
case req := <-w.newWorkCh:
|
case req := <-w.newWorkCh:
|
||||||
//nolint:contextcheck
|
//nolint:contextcheck
|
||||||
if w.isRunning() {
|
w.commitWork(req.ctx, req.interrupt, req.noempty, req.timestamp)
|
||||||
w.commitWork(req.ctx, req.interrupt, req.noempty, req.timestamp)
|
|
||||||
}
|
|
||||||
|
|
||||||
case req := <-w.getWorkCh:
|
case req := <-w.getWorkCh:
|
||||||
//nolint:contextcheck
|
//nolint:contextcheck
|
||||||
|
|
|
||||||
|
|
@ -577,112 +577,90 @@ func TestFetchStateSyncEvents_2(t *testing.T) {
|
||||||
require.Equal(t, uint64(6), lastStateID.Uint64())
|
require.Equal(t, uint64(6), lastStateID.Uint64())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Abs returns the absolute value of x.
|
|
||||||
func Abs(x int) int {
|
|
||||||
if x < 0 {
|
|
||||||
return -x
|
|
||||||
}
|
|
||||||
return x
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestOutOfTurnSigning(t *testing.T) {
|
func TestOutOfTurnSigning(t *testing.T) {
|
||||||
log.Root().SetHandler(log.LvlFilterHandler(log.LvlInfo, log.StreamHandler(os.Stderr, log.TerminalFormat(true))))
|
init := buildEthereumInstance(t, rawdb.NewMemoryDatabase())
|
||||||
fdlimit.Raise(2048)
|
chain := init.ethereum.BlockChain()
|
||||||
|
engine := init.ethereum.Engine()
|
||||||
|
_bor := engine.(*bor.Bor)
|
||||||
|
|
||||||
// Generate a batch of accounts to seal and fund with
|
defer _bor.Close()
|
||||||
faucets := make([]*ecdsa.PrivateKey, 128)
|
|
||||||
for i := 0; i < len(faucets); i++ {
|
|
||||||
faucets[i], _ = crypto.GenerateKey()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create an Ethash network based off of the Ropsten config
|
_, heimdallSpan := loadSpanFromFile(t)
|
||||||
// Generate a batch of accounts to seal and fund with
|
proposer := valset.NewValidator(addr, 10)
|
||||||
genesis := InitGenesis(t, faucets, "./testdata/genesis_2val.json", 8)
|
heimdallSpan.ValidatorSet.Validators = append(heimdallSpan.ValidatorSet.Validators, proposer)
|
||||||
|
|
||||||
var (
|
// add the block producer
|
||||||
stacks []*node.Node
|
h, ctrl := getMockedHeimdallClient(t, heimdallSpan)
|
||||||
nodes []*eth.Ethereum
|
defer ctrl.Finish()
|
||||||
enodes []*enode.Node
|
|
||||||
)
|
|
||||||
for i := 0; i < 2; i++ {
|
|
||||||
// Start the node and wait until it's up
|
|
||||||
stack, ethBackend, err := InitMiner(genesis, keys[i], true)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer stack.Close()
|
|
||||||
|
|
||||||
for stack.Server().NodeInfo().Ports.Listener == 0 {
|
h.EXPECT().Close().AnyTimes()
|
||||||
time.Sleep(250 * time.Millisecond)
|
|
||||||
}
|
|
||||||
// Connect the node to all the previous ones
|
|
||||||
for _, n := range enodes {
|
|
||||||
stack.Server().AddPeer(n)
|
|
||||||
}
|
|
||||||
// Start tracking the node and its enode
|
|
||||||
stacks = append(stacks, stack)
|
|
||||||
nodes = append(nodes, ethBackend)
|
|
||||||
enodes = append(enodes, stack.Server().Self())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Iterate over all the nodes and start mining
|
spanner := getMockedSpanner(t, heimdallSpan.ValidatorSet.Validators)
|
||||||
time.Sleep(3 * time.Second)
|
_bor.SetSpanner(spanner)
|
||||||
for _, node := range nodes {
|
_bor.SetHeimdallClient(h)
|
||||||
if err := node.StartMining(1); err != nil {
|
|
||||||
panic(err)
|
db := init.ethereum.ChainDb()
|
||||||
|
block := init.genesis.ToBlock(db)
|
||||||
|
|
||||||
|
setDifficulty := func(header *types.Header) {
|
||||||
|
if IsSprintStart(header.Number.Uint64()) {
|
||||||
|
header.Difficulty = big.NewInt(int64(len(heimdallSpan.ValidatorSet.Validators)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for i := uint64(1); i < spanSize; i++ {
|
||||||
|
block = buildNextBlock(t, _bor, chain, block, nil, init.genesis.Config.Bor, nil, heimdallSpan.ValidatorSet.Validators, setDifficulty)
|
||||||
// for block 1 to 8, the primary validator is node0
|
insertNewBlock(t, chain, block)
|
||||||
blockHeaderVal0 := nodes[0].BlockChain().CurrentHeader()
|
|
||||||
blockHeaderVal1 := nodes[1].BlockChain().CurrentHeader()
|
|
||||||
|
|
||||||
// we remove peer connection between node0 and node1
|
|
||||||
if blockHeaderVal0.Number.Uint64() == 1 {
|
|
||||||
stacks[0].Server().RemovePeer(enodes[1])
|
|
||||||
}
|
|
||||||
|
|
||||||
if blockHeaderVal1.Number.Uint64() == 9 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// function to get timestamp difference between two nodes of the same blockNumber
|
// insert spanSize-th block
|
||||||
timeDiff := func(blockNum int) int {
|
// This account is one the out-of-turn validators for 1st (0-indexed) span
|
||||||
blockHeaderVal0 := nodes[0].BlockChain().GetHeaderByNumber(uint64(blockNum))
|
signer := "c8deb0bea5c41afe8e37b4d1bd84e31adff11b09c8c96ff4b605003cce067cd9"
|
||||||
blockHeaderVal1 := nodes[1].BlockChain().GetHeaderByNumber(uint64(blockNum))
|
signerKey, _ := hex.DecodeString(signer)
|
||||||
|
newKey, _ := crypto.HexToECDSA(signer)
|
||||||
|
newAddr := crypto.PubkeyToAddress(newKey.PublicKey)
|
||||||
|
expectedSuccessionNumber := 2
|
||||||
|
|
||||||
return Abs(int(blockHeaderVal0.Time - blockHeaderVal1.Time))
|
parentTime := block.Time()
|
||||||
|
|
||||||
|
setParentTime := func(header *types.Header) {
|
||||||
|
header.Time = parentTime + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// check block 10 miner ; expected author is node1 signer
|
const turn = 1
|
||||||
blockHeaderVal0 := nodes[0].BlockChain().GetHeaderByNumber(3)
|
|
||||||
blockHeaderVal1 := nodes[1].BlockChain().GetHeaderByNumber(3)
|
|
||||||
|
|
||||||
// check both nodes have the same block 10
|
setDifficulty = func(header *types.Header) {
|
||||||
assert.Equal(t, blockHeaderVal0.Difficulty, common.Big2)
|
header.Difficulty = big.NewInt(int64(len(heimdallSpan.ValidatorSet.Validators)) - turn)
|
||||||
|
}
|
||||||
|
|
||||||
// check node0 has block mined by node1
|
block = buildNextBlock(t, _bor, chain, block, signerKey, init.genesis.Config.Bor, nil, heimdallSpan.ValidatorSet.Validators, setParentTime, setDifficulty)
|
||||||
assert.Equal(t, blockHeaderVal1.Difficulty, common.Big1)
|
_, err := chain.InsertChain([]*types.Block{block})
|
||||||
|
require.Equal(t,
|
||||||
|
bor.BlockTooSoonError{Number: spanSize, Succession: expectedSuccessionNumber},
|
||||||
|
*err.(*bor.BlockTooSoonError))
|
||||||
|
|
||||||
// node seperated at block 1, so at block 3, node0 should be at 3 seconds, and node1 should be at 5( 1 + 2*2 ) seconds
|
expectedDifficulty := uint64(len(heimdallSpan.ValidatorSet.Validators) - expectedSuccessionNumber - turn) // len(validators) - succession
|
||||||
assert.Equal(t, timeDiff(3), 2)
|
header := block.Header()
|
||||||
|
|
||||||
// check block 10 miner ; expected author is node1 signer
|
diff := bor.CalcProducerDelay(header.Number.Uint64(), expectedSuccessionNumber, init.genesis.Config.Bor)
|
||||||
blockHeaderVal0 = nodes[0].BlockChain().GetHeaderByNumber(7)
|
header.Time += diff
|
||||||
blockHeaderVal1 = nodes[1].BlockChain().GetHeaderByNumber(7)
|
|
||||||
|
|
||||||
// check both nodes have the same block 10
|
sign(t, header, signerKey, init.genesis.Config.Bor)
|
||||||
assert.Equal(t, blockHeaderVal0.Difficulty, common.Big2)
|
|
||||||
|
|
||||||
// check node0 has block mined by node1
|
block = types.NewBlockWithHeader(header)
|
||||||
assert.Equal(t, blockHeaderVal1.Difficulty, common.Big1)
|
|
||||||
|
|
||||||
// node seperated at block 1, so at block 7, node0 should be at 7 seconds, and node1 should be at 13( 1 + 2*6 ) seconds
|
_, err = chain.InsertChain([]*types.Block{block})
|
||||||
assert.Equal(t, timeDiff(7), 6)
|
require.NotNil(t, err)
|
||||||
|
require.Equal(t,
|
||||||
|
bor.WrongDifficultyError{Number: spanSize, Expected: expectedDifficulty, Actual: 3, Signer: newAddr.Bytes()},
|
||||||
|
*err.(*bor.WrongDifficultyError))
|
||||||
|
|
||||||
|
header.Difficulty = new(big.Int).SetUint64(expectedDifficulty)
|
||||||
|
sign(t, header, signerKey, init.genesis.Config.Bor)
|
||||||
|
block = types.NewBlockWithHeader(header)
|
||||||
|
|
||||||
|
_, err = chain.InsertChain([]*types.Block{block})
|
||||||
|
require.Nil(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSignerNotFound(t *testing.T) {
|
func TestSignerNotFound(t *testing.T) {
|
||||||
|
|
@ -1121,18 +1099,11 @@ func TestJaipurFork(t *testing.T) {
|
||||||
|
|
||||||
res, _ := loadSpanFromFile(t)
|
res, _ := loadSpanFromFile(t)
|
||||||
|
|
||||||
currentValidators := []*valset.Validator{valset.NewValidator(addr, 10)}
|
spanner := getMockedSpanner(t, res.Result.ValidatorSet.Validators)
|
||||||
|
|
||||||
spanner := getMockedSpanner(t, currentValidators)
|
|
||||||
_bor.SetSpanner(spanner)
|
_bor.SetSpanner(spanner)
|
||||||
|
|
||||||
for i := uint64(1); i < sprintSize; i++ {
|
for i := uint64(1); i < sprintSize; i++ {
|
||||||
if IsSpanEnd(i) {
|
block = buildNextBlock(t, _bor, chain, block, nil, init.genesis.Config.Bor, nil, res.Result.ValidatorSet.Validators)
|
||||||
currentValidators = res.Result.ValidatorSet.Validators
|
|
||||||
}
|
|
||||||
|
|
||||||
block = buildNextBlock(t, _bor, chain, block, nil, init.genesis.Config.Bor, nil, currentValidators)
|
|
||||||
|
|
||||||
insertNewBlock(t, chain, block)
|
insertNewBlock(t, chain, block)
|
||||||
|
|
||||||
if block.Number().Uint64() == init.genesis.Config.Bor.JaipurBlock.Uint64()-1 {
|
if block.Number().Uint64() == init.genesis.Config.Bor.JaipurBlock.Uint64()-1 {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue