From 6d0deed885174930c2b6a9b57fcf422fd1b652b0 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Wed, 5 Sep 2018 15:39:01 +0200 Subject: [PATCH 1/3] utxonursery test: run tests in parallel --- utxonursery_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/utxonursery_test.go b/utxonursery_test.go index adff6d3e3..5410a55f5 100644 --- a/utxonursery_test.go +++ b/utxonursery_test.go @@ -336,6 +336,8 @@ func init() { } func TestKidOutputSerialization(t *testing.T) { + t.Parallel() + for i, kid := range kidOutputs { var b bytes.Buffer if err := kid.Encode(&b); err != nil { @@ -358,6 +360,8 @@ func TestKidOutputSerialization(t *testing.T) { } func TestBabyOutputSerialization(t *testing.T) { + t.Parallel() + for i, baby := range babyOutputs { var b bytes.Buffer if err := baby.Encode(&b); err != nil { From 3a67fe25522a8ce08d5df13898780015a340cbe1 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Wed, 5 Sep 2018 15:43:01 +0200 Subject: [PATCH 2/3] contractcourt+server: make IncubateOutputs take broadcastHeight --- contractcourt/chain_arbitrator.go | 2 +- contractcourt/channel_arbitrator.go | 2 +- contractcourt/contract_resolvers.go | 10 ++++++++-- server.go | 3 ++- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/contractcourt/chain_arbitrator.go b/contractcourt/chain_arbitrator.go index 3bfbafa1e..db4017356 100644 --- a/contractcourt/chain_arbitrator.go +++ b/contractcourt/chain_arbitrator.go @@ -105,7 +105,7 @@ type ChainArbitratorConfig struct { // absolute/relative item block. IncubateOutputs func(wire.OutPoint, *lnwallet.CommitOutputResolution, *lnwallet.OutgoingHtlcResolution, - *lnwallet.IncomingHtlcResolution) error + *lnwallet.IncomingHtlcResolution, uint32) error // PreimageDB is a global store of all known pre-images. We'll use this // to decide if we should broadcast a commitment transaction to claim diff --git a/contractcourt/channel_arbitrator.go b/contractcourt/channel_arbitrator.go index 55a6e2381..ae3fe9673 100644 --- a/contractcourt/channel_arbitrator.go +++ b/contractcourt/channel_arbitrator.go @@ -648,7 +648,7 @@ func (c *ChannelArbitrator) stateStep(triggerHeight uint32, err = c.cfg.IncubateOutputs( c.cfg.ChanPoint, commitRes, - nil, nil, + nil, nil, triggerHeight, ) if err != nil { // TODO(roasbeef): check for AlreadyExists errors diff --git a/contractcourt/contract_resolvers.go b/contractcourt/contract_resolvers.go index 7b8be4866..3ecc6be99 100644 --- a/contractcourt/contract_resolvers.go +++ b/contractcourt/contract_resolvers.go @@ -152,7 +152,10 @@ func (h *htlcTimeoutResolver) Resolve() (ContractResolver, error) { log.Tracef("%T(%v): incubating htlc output", h, h.htlcResolution.ClaimOutpoint) - err := h.IncubateOutputs(h.ChanPoint, nil, &h.htlcResolution, nil) + err := h.IncubateOutputs( + h.ChanPoint, nil, &h.htlcResolution, nil, + h.broadcastHeight, + ) if err != nil { return nil, err } @@ -568,7 +571,10 @@ func (h *htlcSuccessResolver) Resolve() (ContractResolver, error) { log.Infof("%T(%x): incubating incoming htlc output", h, h.payHash[:]) - err := h.IncubateOutputs(h.ChanPoint, nil, nil, &h.htlcResolution) + err := h.IncubateOutputs( + h.ChanPoint, nil, nil, &h.htlcResolution, + h.broadcastHeight, + ) if err != nil { return nil, err } diff --git a/server.go b/server.go index 525d6d316..48ed123cf 100644 --- a/server.go +++ b/server.go @@ -628,7 +628,8 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB, cc *chainControl, IncubateOutputs: func(chanPoint wire.OutPoint, commitRes *lnwallet.CommitOutputResolution, outHtlcRes *lnwallet.OutgoingHtlcResolution, - inHtlcRes *lnwallet.IncomingHtlcResolution) error { + inHtlcRes *lnwallet.IncomingHtlcResolution, + broadcastHeight uint32) error { var ( inRes []lnwallet.IncomingHtlcResolution From 0a5f982280f9509024a88377df6fe0eaf42241fa Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Wed, 5 Sep 2018 15:49:35 +0200 Subject: [PATCH 3/3] utxonursery: pass broadcastHeight to registerPreschoolConf In this commit IncubateOutputs are given an extra parameter broadcastHeight, which is passed from the server and used when called registerPresschoolConf. Earlier the utxonursery used the bestHeight as height hint in this case, which would be wrong in the cases where we got outputs for incubation which was confirmed below the best height. --- server.go | 1 + utxonursery.go | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/server.go b/server.go index 48ed123cf..4c9ce4c0a 100644 --- a/server.go +++ b/server.go @@ -644,6 +644,7 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB, cc *chainControl, return s.utxoNursery.IncubateOutputs( chanPoint, commitRes, outRes, inRes, + broadcastHeight, ) }, PreimageDB: s.witnessBeacon, diff --git a/utxonursery.go b/utxonursery.go index f3bf362ec..5c801dce6 100644 --- a/utxonursery.go +++ b/utxonursery.go @@ -343,7 +343,8 @@ func (u *utxoNursery) Stop() error { func (u *utxoNursery) IncubateOutputs(chanPoint wire.OutPoint, commitResolution *lnwallet.CommitOutputResolution, outgoingHtlcs []lnwallet.OutgoingHtlcResolution, - incomingHtlcs []lnwallet.IncomingHtlcResolution) error { + incomingHtlcs []lnwallet.IncomingHtlcResolution, + broadcastHeight uint32) error { numHtlcs := len(incomingHtlcs) + len(outgoingHtlcs) var ( @@ -469,7 +470,9 @@ func (u *utxoNursery) IncubateOutputs(chanPoint wire.OutPoint, // kindergarten bucket. if len(kidOutputs) != 0 { for _, kidOutput := range kidOutputs { - err := u.registerPreschoolConf(&kidOutput, u.bestHeight) + err := u.registerPreschoolConf( + &kidOutput, broadcastHeight, + ) if err != nil { return err }