contractcourt: remove the now unused chain actions methods
We still keep the `actionsBucketKey` variable around so current contracts will clean up the existing state once they've been fully resolved.
This commit is contained in:
parent
087e22d817
commit
ea7bae8492
@ -9,7 +9,6 @@ import (
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/coreos/bbolt"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
)
|
||||
@ -82,17 +81,6 @@ type ArbitratorLog interface {
|
||||
// contract resolutions from persistent storage.
|
||||
FetchContractResolutions() (*ContractResolutions, error)
|
||||
|
||||
// LogChainActions stores a set of chain actions which are derived from
|
||||
// our set of active contracts, and the on-chain state. We'll write
|
||||
// this et of cations when: we decide to go on-chain to resolve a
|
||||
// contract, or we detect that the remote party has gone on-chain.
|
||||
LogChainActions(ChainActionMap) error
|
||||
|
||||
// FetchChainActions attempts to fetch the set of previously stored
|
||||
// chain actions. We'll use this upon restart to properly advance our
|
||||
// state machine forward.
|
||||
FetchChainActions() (ChainActionMap, error)
|
||||
|
||||
// WipeHistory is to be called ONLY once *all* contracts have been
|
||||
// fully resolved, and the channel closure if finalized. This method
|
||||
// will delete all on-disk state within the persistent log.
|
||||
@ -720,88 +708,6 @@ func (b *boltArbitratorLog) FetchContractResolutions() (*ContractResolutions, er
|
||||
return c, err
|
||||
}
|
||||
|
||||
// LogChainActions stores a set of chain actions which are derived from our set
|
||||
// of active contracts, and the on-chain state. We'll write this et of cations
|
||||
// when: we decide to go on-chain to resolve a contract, or we detect that the
|
||||
// remote party has gone on-chain.
|
||||
//
|
||||
// NOTE: Part of the ContractResolver interface.
|
||||
func (b *boltArbitratorLog) LogChainActions(actions ChainActionMap) error {
|
||||
return b.db.Batch(func(tx *bbolt.Tx) error {
|
||||
scopeBucket, err := tx.CreateBucketIfNotExists(b.scopeKey[:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
actionsBucket, err := scopeBucket.CreateBucketIfNotExists(
|
||||
actionsBucketKey,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for chainAction, htlcs := range actions {
|
||||
var htlcBuf bytes.Buffer
|
||||
err := channeldb.SerializeHtlcs(&htlcBuf, htlcs...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
actionKey := []byte{byte(chainAction)}
|
||||
err = actionsBucket.Put(actionKey, htlcBuf.Bytes())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// FetchChainActions attempts to fetch the set of previously stored chain
|
||||
// actions. We'll use this upon restart to properly advance our state machine
|
||||
// forward.
|
||||
//
|
||||
// NOTE: Part of the ContractResolver interface.
|
||||
func (b *boltArbitratorLog) FetchChainActions() (ChainActionMap, error) {
|
||||
actionsMap := make(ChainActionMap)
|
||||
|
||||
err := b.db.View(func(tx *bbolt.Tx) error {
|
||||
scopeBucket := tx.Bucket(b.scopeKey[:])
|
||||
if scopeBucket == nil {
|
||||
return errScopeBucketNoExist
|
||||
}
|
||||
|
||||
actionsBucket := scopeBucket.Bucket(actionsBucketKey)
|
||||
if actionsBucket == nil {
|
||||
return errNoActions
|
||||
}
|
||||
|
||||
return actionsBucket.ForEach(func(action, htlcBytes []byte) error {
|
||||
if htlcBytes == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
chainAction := ChainAction(action[0])
|
||||
|
||||
htlcReader := bytes.NewReader(htlcBytes)
|
||||
htlcs, err := channeldb.DeserializeHtlcs(htlcReader)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
actionsMap[chainAction] = htlcs
|
||||
|
||||
return nil
|
||||
})
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return actionsMap, nil
|
||||
}
|
||||
|
||||
// WipeHistory is to be called ONLY once *all* contracts have been fully
|
||||
// resolved, and the channel closure if finalized. This method will delete all
|
||||
// on-disk state within the persistent log.
|
||||
@ -835,7 +741,6 @@ func (b *boltArbitratorLog) WipeHistory() error {
|
||||
return err
|
||||
}
|
||||
if err := scopeBucket.DeleteBucket(contractsBucketKey); err != nil {
|
||||
fmt.Println("nah")
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -15,11 +15,8 @@ import (
|
||||
"github.com/btcsuite/btcd/txscript"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/coreos/bbolt"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -565,133 +562,6 @@ func TestContractResolutionsStorage(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestChainActionStorage tests that were able to properly store a set of chain
|
||||
// actions, and then retrieve the same set of chain actions from disk.
|
||||
func TestChainActionStorage(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// First, we'll create a test instance of the ArbitratorLog
|
||||
// implementation backed by boltdb.
|
||||
testLog, cleanUp, err := newTestBoltArbLog(
|
||||
testChainHash, testChanPoint2,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create test log: %v", err)
|
||||
}
|
||||
defer cleanUp()
|
||||
|
||||
chainActions := ChainActionMap{
|
||||
NoAction: []channeldb.HTLC{
|
||||
{
|
||||
RHash: testPreimage,
|
||||
Amt: lnwire.MilliSatoshi(prand.Uint64()),
|
||||
RefundTimeout: prand.Uint32(),
|
||||
OutputIndex: int32(prand.Uint32()),
|
||||
Incoming: true,
|
||||
HtlcIndex: prand.Uint64(),
|
||||
LogIndex: prand.Uint64(),
|
||||
OnionBlob: make([]byte, 0),
|
||||
Signature: make([]byte, 0),
|
||||
},
|
||||
},
|
||||
HtlcTimeoutAction: []channeldb.HTLC{
|
||||
{
|
||||
RHash: testPreimage,
|
||||
Amt: lnwire.MilliSatoshi(prand.Uint64()),
|
||||
RefundTimeout: prand.Uint32(),
|
||||
OutputIndex: int32(prand.Uint32()),
|
||||
Incoming: true,
|
||||
HtlcIndex: prand.Uint64(),
|
||||
LogIndex: prand.Uint64(),
|
||||
OnionBlob: make([]byte, 0),
|
||||
Signature: make([]byte, 0),
|
||||
},
|
||||
},
|
||||
HtlcClaimAction: []channeldb.HTLC{
|
||||
{
|
||||
RHash: testPreimage,
|
||||
Amt: lnwire.MilliSatoshi(prand.Uint64()),
|
||||
RefundTimeout: prand.Uint32(),
|
||||
OutputIndex: int32(prand.Uint32()),
|
||||
Incoming: true,
|
||||
HtlcIndex: prand.Uint64(),
|
||||
LogIndex: prand.Uint64(),
|
||||
OnionBlob: make([]byte, 0),
|
||||
Signature: make([]byte, 0),
|
||||
},
|
||||
},
|
||||
HtlcFailNowAction: []channeldb.HTLC{
|
||||
{
|
||||
RHash: testPreimage,
|
||||
Amt: lnwire.MilliSatoshi(prand.Uint64()),
|
||||
RefundTimeout: prand.Uint32(),
|
||||
OutputIndex: int32(prand.Uint32()),
|
||||
Incoming: true,
|
||||
HtlcIndex: prand.Uint64(),
|
||||
LogIndex: prand.Uint64(),
|
||||
OnionBlob: make([]byte, 0),
|
||||
Signature: make([]byte, 0),
|
||||
},
|
||||
},
|
||||
HtlcOutgoingWatchAction: []channeldb.HTLC{
|
||||
{
|
||||
RHash: testPreimage,
|
||||
Amt: lnwire.MilliSatoshi(prand.Uint64()),
|
||||
RefundTimeout: prand.Uint32(),
|
||||
OutputIndex: int32(prand.Uint32()),
|
||||
Incoming: true,
|
||||
HtlcIndex: prand.Uint64(),
|
||||
LogIndex: prand.Uint64(),
|
||||
OnionBlob: make([]byte, 0),
|
||||
Signature: make([]byte, 0),
|
||||
},
|
||||
},
|
||||
HtlcIncomingWatchAction: []channeldb.HTLC{
|
||||
{
|
||||
RHash: testPreimage,
|
||||
Amt: lnwire.MilliSatoshi(prand.Uint64()),
|
||||
RefundTimeout: prand.Uint32(),
|
||||
OutputIndex: int32(prand.Uint32()),
|
||||
Incoming: true,
|
||||
HtlcIndex: prand.Uint64(),
|
||||
LogIndex: prand.Uint64(),
|
||||
OnionBlob: make([]byte, 0),
|
||||
Signature: make([]byte, 0),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// With our set of test chain actions constructed, we'll now insert
|
||||
// them into the database, retrieve them, then assert equality with the
|
||||
// set of chain actions create above.
|
||||
if err := testLog.LogChainActions(chainActions); err != nil {
|
||||
t.Fatalf("unable to write chain actions: %v", err)
|
||||
}
|
||||
diskActions, err := testLog.FetchChainActions()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to read chain actions: %v", err)
|
||||
}
|
||||
|
||||
for k, contracts := range chainActions {
|
||||
diskContracts := diskActions[k]
|
||||
if !reflect.DeepEqual(contracts, diskContracts) {
|
||||
t.Fatalf("chain action mismatch: expected %v, got %v",
|
||||
spew.Sdump(contracts), spew.Sdump(diskContracts))
|
||||
}
|
||||
}
|
||||
|
||||
// We'll now delete the state, then attempt to retrieve the set of
|
||||
// chain actions, no resolutions should be found.
|
||||
if err := testLog.WipeHistory(); err != nil {
|
||||
t.Fatalf("unable to wipe log: %v", err)
|
||||
}
|
||||
actions, err := testLog.FetchChainActions()
|
||||
if len(actions) != 0 {
|
||||
t.Fatalf("expected no chain actions, instead found: %v",
|
||||
len(actions))
|
||||
}
|
||||
}
|
||||
|
||||
// TestStateMutation tests that we're able to properly mutate the state of the
|
||||
// log, then retrieve that same mutated state from disk.
|
||||
func TestStateMutation(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user