mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +00:00
fix simulator functions to choose between XDC faker and eth faker
This commit is contained in:
parent
81b6ffabba
commit
9efb89dffb
4 changed files with 8 additions and 12 deletions
|
|
@ -126,7 +126,7 @@ func (b *SimulatedBackend) Rollback() {
|
|||
}
|
||||
|
||||
func (b *SimulatedBackend) rollback() {
|
||||
blocks, _ := core.GenerateChain(b.config, b.blockchain.CurrentBlock(), XDPoS.GetFaker(), b.database, 1, func(int, *core.BlockGen) {})
|
||||
blocks, _ := core.GenerateChain(b.config, b.blockchain.CurrentBlock(), b.blockchain.Engine(), b.database, 1, func(int, *core.BlockGen) {})
|
||||
statedb, _ := b.blockchain.State()
|
||||
|
||||
b.pendingBlock = blocks[0]
|
||||
|
|
@ -343,12 +343,13 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transa
|
|||
panic(fmt.Errorf("invalid transaction nonce: got %d, want %d", tx.Nonce(), nonce))
|
||||
}
|
||||
|
||||
blocks, _ := core.GenerateChain(b.config, b.blockchain.CurrentBlock(), XDPoS.GetFaker(), b.database, 1, func(number int, block *core.BlockGen) {
|
||||
blocks, _ := core.GenerateChain(b.config, b.blockchain.CurrentBlock(), b.blockchain.Engine(), b.database, 1, func(number int, block *core.BlockGen) {
|
||||
for _, tx := range b.pendingBlock.Transactions() {
|
||||
block.AddTxWithChain(b.blockchain, tx)
|
||||
}
|
||||
block.AddTxWithChain(b.blockchain, tx)
|
||||
})
|
||||
|
||||
statedb, _ := b.blockchain.State()
|
||||
|
||||
b.pendingBlock = blocks[0]
|
||||
|
|
@ -428,7 +429,7 @@ func (b *SimulatedBackend) SubscribeFilterLogs(ctx context.Context, query ethere
|
|||
func (b *SimulatedBackend) AdjustTime(adjustment time.Duration) error {
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
blocks, _ := core.GenerateChain(b.config, b.blockchain.CurrentBlock(), XDPoS.GetFaker(), b.database, 1, func(number int, block *core.BlockGen) {
|
||||
blocks, _ := core.GenerateChain(b.config, b.blockchain.CurrentBlock(), b.blockchain.Engine(), b.database, 1, func(number int, block *core.BlockGen) {
|
||||
for _, tx := range b.pendingBlock.Transactions() {
|
||||
block.AddTx(tx)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -264,11 +264,10 @@ func New(config *params.XDPoSConfig, db ethdb.Database) *XDPoS {
|
|||
}
|
||||
}
|
||||
|
||||
var fakeEngine *XDPoS
|
||||
|
||||
// NewFullFaker creates an ethash consensus engine with a full fake scheme that
|
||||
// accepts all blocks as valid, without checking any consensus rules whatsoever.
|
||||
func NewFaker(db ethdb.Database) *XDPoS {
|
||||
var fakeEngine *XDPoS
|
||||
// Set any missing consensus parameters to their defaults
|
||||
conf := params.TestXDPoSMockChainConfig.XDPoS
|
||||
|
||||
|
|
@ -291,10 +290,6 @@ func NewFaker(db ethdb.Database) *XDPoS {
|
|||
return fakeEngine
|
||||
}
|
||||
|
||||
func GetFaker() *XDPoS {
|
||||
return fakeEngine
|
||||
}
|
||||
|
||||
// Author implements consensus.Engine, returning the Ethereum address recovered
|
||||
// from the signature in the header's extra-data section.
|
||||
func (c *XDPoS) Author(header *types.Header) (common.Address, error) {
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ func TestRandomize(t *testing.T) {
|
|||
|
||||
func TestSendTxRandomizeSecretAndOpening(t *testing.T) {
|
||||
genesis := core.GenesisAlloc{acc1Addr: {Balance: big.NewInt(1000000000000)}}
|
||||
backend := backends.NewXDCSimulatedBackend(genesis, 10000000)
|
||||
backend := backends.NewSimulatedBackend(genesis, 10000000)
|
||||
backend.Commit()
|
||||
signer := types.HomesteadSigner{}
|
||||
ctx := context.Background()
|
||||
|
|
|
|||
|
|
@ -1068,7 +1068,7 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.
|
|||
if status == CanonStatTy {
|
||||
bc.insert(block)
|
||||
// prepare set of masternodes for the next epoch
|
||||
if (block.NumberU64() % bc.chainConfig.XDPoS.Epoch) == (bc.chainConfig.XDPoS.Epoch - bc.chainConfig.XDPoS.Gap) {
|
||||
if bc.chainConfig.XDPoS != nil && ((block.NumberU64() % bc.chainConfig.XDPoS.Epoch) == (bc.chainConfig.XDPoS.Epoch - bc.chainConfig.XDPoS.Gap)) {
|
||||
err := bc.UpdateM1()
|
||||
if err != nil {
|
||||
log.Error("Error when update masternodes set. Stopping node", "err", err)
|
||||
|
|
@ -1732,7 +1732,7 @@ func (bc *BlockChain) reorg(oldBlock, newBlock *types.Block) error {
|
|||
rawdb.WriteTxLookupEntries(bc.db, newChain[i])
|
||||
addedTxs = append(addedTxs, newChain[i].Transactions()...)
|
||||
// prepare set of masternodes for the next epoch
|
||||
if (newChain[i].NumberU64() % bc.chainConfig.XDPoS.Epoch) == (bc.chainConfig.XDPoS.Epoch - bc.chainConfig.XDPoS.Gap) {
|
||||
if bc.chainConfig.XDPoS != nil && ((newChain[i].NumberU64() % bc.chainConfig.XDPoS.Epoch) == (bc.chainConfig.XDPoS.Epoch - bc.chainConfig.XDPoS.Gap)) {
|
||||
err := bc.UpdateM1()
|
||||
if err != nil {
|
||||
log.Crit("Error when update masternodes set. Stopping node", "err", err)
|
||||
|
|
|
|||
Loading…
Reference in a new issue