Skip to content

Commit

Permalink
Add tx gossip test
Browse files Browse the repository at this point in the history
  • Loading branch information
pcw109550 committed May 16, 2023
1 parent 54badac commit 900857f
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions simulators/optimism/p2p/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,86 @@ func main() {
Description: `This test verifies that tx forwarding works`,
Run: func(t *hivesim.T) { txForwardingTest(t) },
})
suite.Add(&hivesim.TestSpec{
Name: "tx gossiping",
Description: `This test verifies that tx gossiping works`,
Run: func(t *hivesim.T) { txGossipingTest(t) },
})

sim := hivesim.New()
hivesim.MustRunSuite(sim, suite)
}

// txGossipingTest verifies that a transaction submitted to a replica execution client
// with tx gossiping enabled shows up on the sequencer tx pool.
func txGossipingTest(t *hivesim.T) {
d := optimism.NewDevnet(t)
sender := d.L2Vault.GenerateKey()
receiver := d.L2Vault.GenerateKey()

d.InitChain(30, 4, 30, core.GenesisAlloc{sender: {Balance: big.NewInt(params.Ether)}})
d.AddEth1()
d.WaitUpEth1(0, time.Second*10)

d.AddOpL2()
d.AddOpNode(0, 0, false)
seqNode := d.GetOpL2Engine(0)

d.AddOpL2()
d.AddOpNode(0, 1, false)
verifNode := d.GetOpL2Engine(1)
verifClient := verifNode.EthClient()

var wg sync.WaitGroup
wg.Add(2)

go func() {
d.WaitUpOpL2Engine(0, time.Second*10)
wg.Done()
}()
go func() {
d.WaitUpOpL2Engine(1, time.Second*10)
wg.Done()
}()

t.Log("waiting for nodes to come up")
wg.Wait()

t.Logf("peering execution clients %s with %s", seqNode.IP.String(), verifNode.IP.String())
seqNodeExtended := &optimism.OpL2EngineExtended{OpL2Engine: seqNode}
verifNodeExtended := &optimism.OpL2EngineExtended{OpL2Engine: verifNode}
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
require.NoError(t, seqNodeExtended.ConnectPeer(ctx, verifNodeExtended))

baseTx := types.NewTx(&types.DynamicFeeTx{
ChainID: optimism.L2ChainIDBig,
Nonce: 0,
To: &receiver,
Gas: 75000,
GasTipCap: big.NewInt(10 * params.GWei),
GasFeeCap: big.NewInt(20 * params.GWei),
Value: big.NewInt(0.0001 * params.Ether),
})

tx, err := d.L2Vault.SignTransaction(sender, baseTx)
require.Nil(t, err)
ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
require.NoError(t, verifClient.SendTransaction(ctx, tx))
t.Log("sent tx to verifier, waiting for tx gossip")

<-time.After(10 * time.Second)

ctx, cancel = context.WithTimeout(context.Background(), 180*time.Second)
defer cancel()
found, err := optimism.WaitPendingTransactionFromTxPool(ctx, seqNodeExtended, sender, tx)
if !found {
t.Fatal("transaction not gossiped", "err", err)
}
t.Log("found gossiped transaction on sequencer")
}

// txForwardingTest verifies that a transaction submitted to a replica with tx forwarding enabled shows up on the sequencer.
// TODO: The transaction shows up with `getTransaction`, but it remains pending and is not mined for some reason.
// This is weird, but fine because it still shows that the transaction is received by the sequencer.
Expand Down

0 comments on commit 900857f

Please sign in to comment.