Skip to content

Commit

Permalink
l2 keystone mining fixes
Browse files Browse the repository at this point in the history
* generate 5000 blocks to start network test, to make it less likely that we will choose a premature utxo
* give time for l2 keystone to be mined

fixes #2
  • Loading branch information
ClaytonNorthey92 committed Feb 28, 2024
1 parent b3993a0 commit f88485d
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions e2e/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func TestFullNetwork(t *testing.T) {
"-rpcuser=user",
"-rpcpassword=password",
"generatetoaddress",
"300", // need to generate a lot for greater chance to not spend coinbase
"5000", // need to generate a lot for greater chance to not spend coinbase
btcAddress.EncodeAddress(),
})
if err != nil {
Expand Down Expand Up @@ -213,11 +213,10 @@ func TestFullNetwork(t *testing.T) {
}()

go func() {
// create a new block every second, then view pop payouts and finalities

firstL2Keystone := hemi.L2KeystoneAbbreviate(l2Keystone).Serialize()

for {
l2Keystone.L2BlockNumber++
l2Keystone.L1BlockNumber++

l2KeystoneRequest := bssapi.L2KeystoneRequest{
L2Keystone: l2Keystone,
}
Expand All @@ -228,6 +227,14 @@ func TestFullNetwork(t *testing.T) {
return
}

// give time for the L2 Keystone to propogate to bitcoin tx mempool
select {
case <-time.After(10 * time.Second):
case <-ctx.Done():
panic(ctx.Err())
}

// generate a new btc block, this should include the l2 keystone
err = runBitcoinCommand(ctx,
t,
bitcoindContainer,
Expand All @@ -246,21 +253,17 @@ func TestFullNetwork(t *testing.T) {
return
}

l2Keystone.L1BlockNumber++
l2Keystone.L2BlockNumber++

time.Sleep(1 * time.Second)

err = bssapi.Write(ctx, bws.conn, "someotherid", bssapi.PopPayoutsRequest{
L2BlockForPayout: firstL2Keystone[:],
})
if err != nil {
t.Logf("error: %s", err)
return
// give time for bfg to see the new block
select {
case <-time.After(10 * time.Second):
case <-ctx.Done():
panic(ctx.Err())
}

err = bssapi.Write(ctx, bws.conn, "someotheridz", bssapi.BTCFinalityByRecentKeystonesRequest{
NumRecentKeystones: 100,
// ensure the l2 keystone is in the chain
ks := hemi.L2KeystoneAbbreviate(l2Keystone).Serialize()
err = bssapi.Write(ctx, bws.conn, "someotherid", bssapi.PopPayoutsRequest{
L2BlockForPayout: ks[:],
})
if err != nil {
t.Logf("error: %s", err)
Expand Down

0 comments on commit f88485d

Please sign in to comment.