Skip to content

Commit

Permalink
l2 keystone mining fixes
Browse files Browse the repository at this point in the history
* generate 1000 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
* do not continue if we have found a pop tx in a wire msg tx without error

fixes #2
  • Loading branch information
ClaytonNorthey92 committed Feb 27, 2024
1 parent b3993a0 commit fa49615
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
36 changes: 14 additions & 22 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
"1000", // need to generate a lot for greater chance to not spend coinbase
btcAddress.EncodeAddress(),
})
if err != nil {
Expand Down Expand Up @@ -212,22 +212,22 @@ func TestFullNetwork(t *testing.T) {
}
}()

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

firstL2Keystone := hemi.L2KeystoneAbbreviate(l2Keystone).Serialize()
l2KeystoneRequest := bssapi.L2KeystoneRequest{
L2Keystone: l2Keystone,
}

go func() {
for {
l2KeystoneRequest := bssapi.L2KeystoneRequest{
L2Keystone: l2Keystone,
}

err = bssapi.Write(ctx, bws.conn, "someid", l2KeystoneRequest)
if err != nil {
t.Logf("error: %s", err)
return
}

// give time for the L2 Keystone to propogate to bitcoin tx mempool
time.Sleep(10 * time.Second)

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

l2Keystone.L1BlockNumber++
l2Keystone.L2BlockNumber++

time.Sleep(1 * time.Second)
// give time for bfg to see the new block
time.Sleep(10 * time.Second)

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

err = bssapi.Write(ctx, bws.conn, "someotheridz", bssapi.BTCFinalityByRecentKeystonesRequest{
NumRecentKeystones: 100,
L2BlockForPayout: ks[:],
})
if err != nil {
t.Logf("error: %s", err)
Expand Down
2 changes: 2 additions & 0 deletions service/bfg/bfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ func (s *Server) handleBitcoinBroadcast(ctx context.Context, bws *bfgWs, payload
tl2, err = pop.ParseTransactionL2FromOpReturn(v.PkScript)
if err != nil {
log.Errorf(err.Error()) // handle real error below
} else {
break
}
}
if tl2 == nil {
Expand Down

0 comments on commit fa49615

Please sign in to comment.