channeldb: re-design OpenChannel schema, update tests
The state of OpenChannel on disk has now been partitioned into several buckets+keys within the db. At the top level, a set of prefixed keys stored common data updated frequently (with every channel update). These fields are stored at the top level in order to facilities prefix scans, and to avoid read/write amplification due to serialization/deserialization with each read/write. Within the active channel bucket, a nested bucket keyed on the node’s ID stores the remainder of the channel. Additionally OpenChannel now uses elkrem rather than shachain, delivery scripts instead of addresses, stores the total net fees, and splits the csv delay into the remote vs local node’s. Several TODO’s have been left lingering, to be visited in the near future.
This commit is contained in:
1 parent
631e76519e
commit
87603e780f
4 files changed
+686
-330
No files matched your search
+5
-3
@@ -6,17 +6,19 @@ import (
|
||||
"golang.org/x/crypto/ripemd160"
|
||||
|
||||
"github.com/boltdb/bolt"
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcutil"
|
||||
)
|
||||
|
||||
var (
|
||||
idBucket = []byte("i")
|
||||
idBucket = []byte("i")
|
||||
ActiveNetParams = &chaincfg.TestNet3Params
|
||||
)
|
||||
|
||||
// PutIdKey saves the hash160 of the public key used for our identity within
|
||||
// the Lightning Network.
|
||||
func (d *DB) PutIdKey(pkh []byte) error {
|
||||
return d.db.Update(func(tx *bolt.Tx) error {
|
||||
return d.store.Update(func(tx *bolt.Tx) error {
|
||||
// Get the bucket dedicated to storing the meta-data for open
|
||||
// channels.
|
||||
bucket, err := tx.CreateBucketIfNotExists(idBucket)
|
||||
@@ -32,7 +34,7 @@ func (d *DB) PutIdKey(pkh []byte) error {
|
||||
// the Lightning Network as a p2pkh bitcoin address.
|
||||
func (d *DB) GetIdAdr() (*btcutil.AddressPubKeyHash, error) {
|
||||
pkh := make([]byte, ripemd160.Size)
|
||||
err := d.db.View(func(tx *bolt.Tx) error {
|
||||
err := d.store.View(func(tx *bolt.Tx) error {
|
||||
// Get the bucket dedicated to storing the meta-data for open
|
||||
// channels.
|
||||
bucket := tx.Bucket(idBucket)
|
||||
|
||||
Reference in new issue
Block a user