From 56fb41476775028d11b3c1a6f75a9d98394ad548 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 12 Jul 2016 17:26:49 -0700 Subject: [PATCH] channeldb: add method to sync revocation state to disk --- channeldb/channel.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/channeldb/channel.go b/channeldb/channel.go index 982fe46de..945f1f624 100644 --- a/channeldb/channel.go +++ b/channeldb/channel.go @@ -204,6 +204,34 @@ func (c *OpenChannel) FullSync() error { }) } +// SyncRevocation writes to disk the current revocation state of the channel. +// The revocation state is defined as the current elkrem receiver, and the +// latest unrevoked key+hash for the remote party. +func (c *OpenChannel) SyncRevocation() error { + return c.Db.store.Update(func(tx *bolt.Tx) error { + // First fetch the top level bucket which stores all data related to + // current, active channels. + chanBucket, err := tx.CreateBucketIfNotExists(openChannelBucket) + if err != nil { + return err + } + + // Within this top level bucket, fetch the bucket dedicated to storing + // open channel data specific to the remote node. + nodeChanBucket, err := chanBucket.CreateBucketIfNotExists(c.TheirLNID[:]) + if err != nil { + return err + } + + // Sync the current elkrem state to disk. + if err := putChanEklremState(nodeChanBucket, c); err != nil { + return err + } + + return nil + }) +} + // CloseChannel closes a previously active lightning channel. Closing a channel // entails deleting all saved state within the database concerning this // channel, as well as created a small channel summary for record keeping