Skip to content

Commit

Permalink
another approach to gossip/testEnv.BlockTxs()
Browse files Browse the repository at this point in the history
  • Loading branch information
rus-alex committed Feb 10, 2024
1 parent ff09e6e commit f0b3bdd
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions gossip/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/Fantom-foundation/lachesis-base/hash"
"github.com/Fantom-foundation/lachesis-base/inter/dag"
"github.com/Fantom-foundation/lachesis-base/inter/idx"
"github.com/Fantom-foundation/lachesis-base/lachesis"
"github.com/Fantom-foundation/lachesis-base/utils/cachescale"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
Expand Down Expand Up @@ -228,7 +229,31 @@ func (env *testEnv) ApplyTxs(spent time.Duration, txs ...*types.Transaction) (ty
}

func (env *testEnv) BlockTxs(spent time.Duration, txs ...*types.Transaction) (types.Receipts, error) {
return env.applyTxs(spent, true, txs...)
// Just `env.applyTxs(spent, true, txs...)` does not work guaranteed because of gas rules.
// So we make single-event block and skip emitting process.
env.t = env.t.Add(spent)

mutEvent := &inter.MutableEventPayload{}
mutEvent.SetVersion(1) // LLR
mutEvent.SetEpoch(env.store.GetEpoch())
mutEvent.SetCreationTime(inter.Timestamp(env.t.UnixNano()))
mutEvent.SetTxs(types.Transactions(txs))
event := mutEvent.Build()
env.store.SetEvent(event)

consensus := env.Service.GetConsensusCallbacks()
blockCallback := consensus.BeginBlock(&lachesis.Block{
Atropos: event.ID(),
Cheaters: make([]idx.ValidatorID, 0),
})
blockCallback.ApplyEvent(event)
blockCallback.EndBlock()
env.blockProcWg.Wait()

number := env.store.GetBlockIndex(event.ID())
block := env.GetEvmStateReader().GetBlock(common.Hash{}, uint64(*number))
receipts := env.store.evm.GetReceipts(*number, env.EthAPI.signer, block.Hash, block.Transactions)
return receipts, nil
}

func (env *testEnv) applyTxs(spent time.Duration, singleBlock bool, txs ...*types.Transaction) (types.Receipts, error) {
Expand All @@ -255,7 +280,7 @@ func (env *testEnv) applyTxs(spent time.Duration, singleBlock bool, txs ...*type
for _, tx := range e.Txs() {
h := tx.Hash()
delete(waitForInEvents, h)
// env.txpool.(*dummyTxPool).Delete(tx.Hash())
env.txpool.(*dummyTxPool).Delete(tx.Hash())
}
}
}()
Expand Down

0 comments on commit f0b3bdd

Please sign in to comment.