From 8c8f857f60e9ef51c59c4e2d874df0fb54f47d35 Mon Sep 17 00:00:00 2001 From: carla Date: Tue, 7 Jul 2020 19:49:50 +0200 Subject: [PATCH] contractcourt: add PutResolverReport function to chanArb config --- contractcourt/briefcase_test.go | 7 ++++++- contractcourt/chain_arbitrator.go | 16 ++++++++++++++++ contractcourt/channel_arbitrator.go | 7 +++++++ contractcourt/channel_arbitrator_test.go | 5 +++++ contractcourt/commit_sweep_resolver_test.go | 7 +++++++ contractcourt/htlc_incoming_resolver_test.go | 11 ++++++++--- .../htlc_outgoing_contest_resolver_test.go | 6 ++++++ contractcourt/htlc_timeout_resolver_test.go | 7 +++++++ 8 files changed, 62 insertions(+), 4 deletions(-) diff --git a/contractcourt/briefcase_test.go b/contractcourt/briefcase_test.go index 165016d3..446110dd 100644 --- a/contractcourt/briefcase_test.go +++ b/contractcourt/briefcase_test.go @@ -133,7 +133,12 @@ func newTestBoltArbLog(chainhash chainhash.Hash, return nil, nil, err } - testArbCfg := ChannelArbitratorConfig{} + testArbCfg := ChannelArbitratorConfig{ + PutResolverReport: func(_ kvdb.RwTx, + _ *channeldb.ResolverReport) error { + return nil + }, + } testLog, err := newBoltArbitratorLog(testDB, testArbCfg, chainhash, op) if err != nil { return nil, nil, err diff --git a/contractcourt/chain_arbitrator.go b/contractcourt/chain_arbitrator.go index f5979ed8..dacbc1f5 100644 --- a/contractcourt/chain_arbitrator.go +++ b/contractcourt/chain_arbitrator.go @@ -12,6 +12,7 @@ import ( "github.com/btcsuite/btcutil" "github.com/lightningnetwork/lnd/chainntnfs" "github.com/lightningnetwork/lnd/channeldb" + "github.com/lightningnetwork/lnd/channeldb/kvdb" "github.com/lightningnetwork/lnd/clock" "github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/lnwallet" @@ -347,6 +348,14 @@ func newActiveChannelArbitrator(channel *channeldb.OpenChannel, IsPendingClose: false, ChainArbitratorConfig: c.cfg, ChainEvents: chanEvents, + PutResolverReport: func(tx kvdb.RwTx, + report *channeldb.ResolverReport) error { + + return c.chanSource.PutResolverReport( + tx, c.cfg.ChainHash, &channel.FundingOutpoint, + report, + ) + }, } // The final component needed is an arbitrator log that the arbitrator @@ -552,6 +561,13 @@ func (c *ChainArbitrator) Start() error { IsPendingClose: true, ClosingHeight: closeChanInfo.CloseHeight, CloseType: closeChanInfo.CloseType, + PutResolverReport: func(tx kvdb.RwTx, + report *channeldb.ResolverReport) error { + + return c.chanSource.PutResolverReport( + tx, c.cfg.ChainHash, &chanPoint, report, + ) + }, } chanLog, err := newBoltArbitratorLog( c.chanSource.Backend, arbCfg, c.cfg.ChainHash, chanPoint, diff --git a/contractcourt/channel_arbitrator.go b/contractcourt/channel_arbitrator.go index 68909673..eba962e8 100644 --- a/contractcourt/channel_arbitrator.go +++ b/contractcourt/channel_arbitrator.go @@ -13,6 +13,7 @@ import ( "github.com/davecgh/go-spew/spew" "github.com/lightningnetwork/lnd/chainntnfs" "github.com/lightningnetwork/lnd/channeldb" + "github.com/lightningnetwork/lnd/channeldb/kvdb" "github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/lntypes" "github.com/lightningnetwork/lnd/lnwallet" @@ -143,6 +144,12 @@ type ChannelArbitratorConfig struct { // TODO(roasbeef): need RPC's to combine for pendingchannels RPC MarkChannelResolved func() error + // PutResolverReport records a resolver report for the channel. If the + // transaction provided is nil, the function should write the report + // in a new transaction. + PutResolverReport func(tx kvdb.RwTx, + report *channeldb.ResolverReport) error + ChainArbitratorConfig } diff --git a/contractcourt/channel_arbitrator_test.go b/contractcourt/channel_arbitrator_test.go index f71aa172..c9af5416 100644 --- a/contractcourt/channel_arbitrator_test.go +++ b/contractcourt/channel_arbitrator_test.go @@ -380,6 +380,11 @@ func createTestChannelArbitrator(t *testing.T, log ArbitratorLog, IsPendingClose: false, ChainArbitratorConfig: chainArbCfg, ChainEvents: chanEvents, + PutResolverReport: func(_ kvdb.RwTx, + _ *channeldb.ResolverReport) error { + + return nil + }, } // Apply all custom options to the config struct. diff --git a/contractcourt/commit_sweep_resolver_test.go b/contractcourt/commit_sweep_resolver_test.go index 866cb22b..109f62fd 100644 --- a/contractcourt/commit_sweep_resolver_test.go +++ b/contractcourt/commit_sweep_resolver_test.go @@ -7,6 +7,8 @@ import ( "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" "github.com/lightningnetwork/lnd/chainntnfs" + "github.com/lightningnetwork/lnd/channeldb" + "github.com/lightningnetwork/lnd/channeldb/kvdb" "github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwallet/chainfee" @@ -39,6 +41,11 @@ func newCommitSweepResolverTestContext(t *testing.T, Notifier: notifier, Sweeper: sweeper, }, + PutResolverReport: func(_ kvdb.RwTx, + _ *channeldb.ResolverReport) error { + + return nil + }, } cfg := ResolverConfig{ diff --git a/contractcourt/htlc_incoming_resolver_test.go b/contractcourt/htlc_incoming_resolver_test.go index 400662d7..9b6555ae 100644 --- a/contractcourt/htlc_incoming_resolver_test.go +++ b/contractcourt/htlc_incoming_resolver_test.go @@ -6,13 +6,13 @@ import ( "io/ioutil" "testing" + "github.com/lightningnetwork/lnd/chainntnfs" "github.com/lightningnetwork/lnd/channeldb" + "github.com/lightningnetwork/lnd/channeldb/kvdb" "github.com/lightningnetwork/lnd/htlcswitch/hop" "github.com/lightningnetwork/lnd/invoices" - "github.com/lightningnetwork/lnd/lnwallet" - - "github.com/lightningnetwork/lnd/chainntnfs" "github.com/lightningnetwork/lnd/lntypes" + "github.com/lightningnetwork/lnd/lnwallet" ) const ( @@ -251,6 +251,11 @@ func newIncomingResolverTestContext(t *testing.T) *incomingResolverTestContext { Registry: registry, OnionProcessor: onionProcessor, }, + PutResolverReport: func(_ kvdb.RwTx, + _ *channeldb.ResolverReport) error { + + return nil + }, } cfg := ResolverConfig{ diff --git a/contractcourt/htlc_outgoing_contest_resolver_test.go b/contractcourt/htlc_outgoing_contest_resolver_test.go index 3a6c1ea5..a689f5d7 100644 --- a/contractcourt/htlc_outgoing_contest_resolver_test.go +++ b/contractcourt/htlc_outgoing_contest_resolver_test.go @@ -7,6 +7,7 @@ import ( "github.com/btcsuite/btcd/wire" "github.com/lightningnetwork/lnd/chainntnfs" "github.com/lightningnetwork/lnd/channeldb" + "github.com/lightningnetwork/lnd/channeldb/kvdb" "github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/lntypes" "github.com/lightningnetwork/lnd/lnwallet" @@ -117,6 +118,11 @@ func newOutgoingResolverTestContext(t *testing.T) *outgoingResolverTestContext { }, OnionProcessor: onionProcessor, }, + PutResolverReport: func(_ kvdb.RwTx, + _ *channeldb.ResolverReport) error { + + return nil + }, } outgoingRes := lnwallet.OutgoingHtlcResolution{ diff --git a/contractcourt/htlc_timeout_resolver_test.go b/contractcourt/htlc_timeout_resolver_test.go index 923fb3ea..9445b1a2 100644 --- a/contractcourt/htlc_timeout_resolver_test.go +++ b/contractcourt/htlc_timeout_resolver_test.go @@ -11,6 +11,8 @@ import ( "github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcd/wire" "github.com/lightningnetwork/lnd/chainntnfs" + "github.com/lightningnetwork/lnd/channeldb" + "github.com/lightningnetwork/lnd/channeldb/kvdb" "github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/lntypes" "github.com/lightningnetwork/lnd/lnwallet" @@ -248,6 +250,11 @@ func TestHtlcTimeoutResolver(t *testing.T) { return nil }, }, + PutResolverReport: func(_ kvdb.RwTx, + _ *channeldb.ResolverReport) error { + + return nil + }, } cfg := ResolverConfig{