mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 10:50:44 +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() {
|
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()
|
statedb, _ := b.blockchain.State()
|
||||||
|
|
||||||
b.pendingBlock = blocks[0]
|
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))
|
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() {
|
for _, tx := range b.pendingBlock.Transactions() {
|
||||||
block.AddTxWithChain(b.blockchain, tx)
|
block.AddTxWithChain(b.blockchain, tx)
|
||||||
}
|
}
|
||||||
block.AddTxWithChain(b.blockchain, tx)
|
block.AddTxWithChain(b.blockchain, tx)
|
||||||
})
|
})
|
||||||
|
|
||||||
statedb, _ := b.blockchain.State()
|
statedb, _ := b.blockchain.State()
|
||||||
|
|
||||||
b.pendingBlock = blocks[0]
|
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 {
|
func (b *SimulatedBackend) AdjustTime(adjustment time.Duration) error {
|
||||||
b.mu.Lock()
|
b.mu.Lock()
|
||||||
defer b.mu.Unlock()
|
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() {
|
for _, tx := range b.pendingBlock.Transactions() {
|
||||||
block.AddTx(tx)
|
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
|
// NewFullFaker creates an ethash consensus engine with a full fake scheme that
|
||||||
// accepts all blocks as valid, without checking any consensus rules whatsoever.
|
// accepts all blocks as valid, without checking any consensus rules whatsoever.
|
||||||
func NewFaker(db ethdb.Database) *XDPoS {
|
func NewFaker(db ethdb.Database) *XDPoS {
|
||||||
|
var fakeEngine *XDPoS
|
||||||
// Set any missing consensus parameters to their defaults
|
// Set any missing consensus parameters to their defaults
|
||||||
conf := params.TestXDPoSMockChainConfig.XDPoS
|
conf := params.TestXDPoSMockChainConfig.XDPoS
|
||||||
|
|
||||||
|
|
@ -291,10 +290,6 @@ func NewFaker(db ethdb.Database) *XDPoS {
|
||||||
return fakeEngine
|
return fakeEngine
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetFaker() *XDPoS {
|
|
||||||
return fakeEngine
|
|
||||||
}
|
|
||||||
|
|
||||||
// Author implements consensus.Engine, returning the Ethereum address recovered
|
// Author implements consensus.Engine, returning the Ethereum address recovered
|
||||||
// from the signature in the header's extra-data section.
|
// from the signature in the header's extra-data section.
|
||||||
func (c *XDPoS) Author(header *types.Header) (common.Address, error) {
|
func (c *XDPoS) Author(header *types.Header) (common.Address, error) {
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ func TestRandomize(t *testing.T) {
|
||||||
|
|
||||||
func TestSendTxRandomizeSecretAndOpening(t *testing.T) {
|
func TestSendTxRandomizeSecretAndOpening(t *testing.T) {
|
||||||
genesis := core.GenesisAlloc{acc1Addr: {Balance: big.NewInt(1000000000000)}}
|
genesis := core.GenesisAlloc{acc1Addr: {Balance: big.NewInt(1000000000000)}}
|
||||||
backend := backends.NewXDCSimulatedBackend(genesis, 10000000)
|
backend := backends.NewSimulatedBackend(genesis, 10000000)
|
||||||
backend.Commit()
|
backend.Commit()
|
||||||
signer := types.HomesteadSigner{}
|
signer := types.HomesteadSigner{}
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
|
||||||
|
|
@ -1068,7 +1068,7 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.
|
||||||
if status == CanonStatTy {
|
if status == CanonStatTy {
|
||||||
bc.insert(block)
|
bc.insert(block)
|
||||||
// prepare set of masternodes for the next epoch
|
// 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()
|
err := bc.UpdateM1()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error when update masternodes set. Stopping node", "err", err)
|
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])
|
rawdb.WriteTxLookupEntries(bc.db, newChain[i])
|
||||||
addedTxs = append(addedTxs, newChain[i].Transactions()...)
|
addedTxs = append(addedTxs, newChain[i].Transactions()...)
|
||||||
// prepare set of masternodes for the next epoch
|
// 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()
|
err := bc.UpdateM1()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Crit("Error when update masternodes set. Stopping node", "err", err)
|
log.Crit("Error when update masternodes set. Stopping node", "err", err)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue