channeldb: add storing of node signature and add edge signature

In order to properly announce the channel the announcements proofs
should be persistent in boltdb.
This commit is contained in:
Andrey Samokhvalov 2017-03-27 18:01:12 +03:00 committed by Olaoluwa Osuntokun
parent 2105a06a26
commit 19174ebdfd
4 changed files with 46 additions and 0 deletions

View File

@ -1108,6 +1108,10 @@ func (p *ChannelAuthProof) IsEmpty() bool {
// information concerning fees, and minimum time-lock information which is
// utilized during path finding.
type ChannelEdgePolicy struct {
// Signature is a channel announcement signature, which is needed for
// proper edge policy announcement.
Signature *btcec.Signature
// ChannelID is the unique channel ID for the channel. The first 3
// bytes are the block height, the next 3 the index within the block,
// and the last 2 bytes are the output index for the channel.
@ -1361,6 +1365,11 @@ func putLightningNode(nodeBucket *bolt.Bucket, aliasBucket *bolt.Bucket, node *L
}
}
err := wire.WriteVarBytes(&b, 0, node.AuthSig.Serialize())
if err != nil {
return err
}
return nodeBucket.Put(nodePub, b.Bytes())
}
@ -1462,6 +1471,16 @@ func deserializeLightningNode(r io.Reader) (*LightningNode, error) {
}
node.Addresses = addresses
sigBytes, err := wire.ReadVarBytes(r, 0, 80, "sig")
if err != nil {
return nil, err
}
node.AuthSig, err = btcec.ParseSignature(sigBytes, btcec.S256())
if err != nil {
return nil, err
}
return node, nil
}
@ -1626,6 +1645,11 @@ func putChanEdgePolicy(edges *bolt.Bucket, edge *ChannelEdgePolicy, from, to []b
var b bytes.Buffer
err := wire.WriteVarBytes(&b, 0, edge.Signature.Serialize())
if err != nil {
return err
}
if err := binary.Write(&b, byteOrder, edge.ChannelID); err != nil {
return err
}
@ -1723,6 +1747,16 @@ func deserializeChanEdgePolicy(r io.Reader,
edge := &ChannelEdgePolicy{}
sigBytes, err := wire.ReadVarBytes(r, 0, 80, "sig")
if err != nil {
return nil, err
}
edge.Signature, err = btcec.ParseSignature(sigBytes, btcec.S256())
if err != nil {
return nil, err
}
if err := binary.Read(r, byteOrder, &edge.ChannelID); err != nil {
return nil, err
}

View File

@ -50,6 +50,7 @@ func createTestVertex(db *DB) (*LightningNode, error) {
pub := priv.PubKey().SerializeCompressed()
return &LightningNode{
AuthSig: testSig,
LastUpdate: time.Unix(updateTime, 0),
PubKey: priv.PubKey(),
Color: color.RGBA{1, 2, 3, 0},
@ -73,6 +74,7 @@ func TestNodeInsertionAndDeletion(t *testing.T) {
// graph, so we'll create a test vertex to start with.
_, testPub := btcec.PrivKeyFromBytes(btcec.S256(), key[:])
node := &LightningNode{
AuthSig: testSig,
LastUpdate: time.Unix(1232342, 0),
PubKey: testPub,
Color: color.RGBA{1, 2, 3, 0},
@ -400,6 +402,7 @@ func TestEdgeInfoUpdates(t *testing.T) {
// With the edge added, we can now create some fake edge information to
// update for both edges.
edge1 := &ChannelEdgePolicy{
Signature: testSig,
ChannelID: chanID,
LastUpdate: time.Unix(433453, 0),
Flags: 0,
@ -411,6 +414,7 @@ func TestEdgeInfoUpdates(t *testing.T) {
db: db,
}
edge2 := &ChannelEdgePolicy{
Signature: testSig,
ChannelID: chanID,
LastUpdate: time.Unix(124234, 0),
Flags: 1,
@ -589,6 +593,7 @@ func TestGraphTraversal(t *testing.T) {
edge := randEdgePolicy(chanID, op, db)
edge.Flags = 0
edge.Node = secondNode
edge.Signature = testSig
if err := graph.UpdateEdgePolicy(edge); err != nil {
t.Fatalf("unable to update edge: %v", err)
}
@ -598,6 +603,7 @@ func TestGraphTraversal(t *testing.T) {
edge = randEdgePolicy(chanID, op, db)
edge.Flags = 1
edge.Node = firstNode
edge.Signature = testSig
if err := graph.UpdateEdgePolicy(edge); err != nil {
t.Fatalf("unable to update edge: %v", err)
}
@ -743,6 +749,7 @@ func TestGraphPruning(t *testing.T) {
edge := randEdgePolicy(chanID, op, db)
edge.Flags = 0
edge.Node = graphNodes[i]
edge.Signature = testSig
if err := graph.UpdateEdgePolicy(edge); err != nil {
t.Fatalf("unable to update edge: %v", err)
}
@ -752,6 +759,7 @@ func TestGraphPruning(t *testing.T) {
edge = randEdgePolicy(chanID, op, db)
edge.Flags = 1
edge.Node = graphNodes[i]
edge.Signature = testSig
if err := graph.UpdateEdgePolicy(edge); err != nil {
t.Fatalf("unable to update edge: %v", err)
}

View File

@ -49,6 +49,7 @@ func createGraphNode() (*channeldb.LightningNode, error) {
PubKey: priv.PubKey(),
Color: color.RGBA{1, 2, 3, 0},
Alias: "kek" + string(pub[:]),
AuthSig: testSig,
Features: testFeatures,
}, nil
}
@ -79,6 +80,7 @@ func randEdgePolicy(chanID lnwire.ShortChannelID,
node *channeldb.LightningNode) *channeldb.ChannelEdgePolicy {
return &channeldb.ChannelEdgePolicy{
Signature: testSig,
ChannelID: chanID.ToUint64(),
LastUpdate: time.Unix(int64(prand.Int31()), 0),
TimeLockDelta: uint16(prand.Int63()),

View File

@ -163,6 +163,7 @@ func parseTestGraph(path string) (*channeldb.ChannelGraph, func(), aliasMap, err
}
dbNode := &channeldb.LightningNode{
AuthSig: testSig,
LastUpdate: time.Now(),
Addresses: testAddrs,
PubKey: pub,
@ -257,6 +258,7 @@ func parseTestGraph(path string) (*channeldb.ChannelGraph, func(), aliasMap, err
}
edgePolicy := &channeldb.ChannelEdgePolicy{
Signature: testSig,
ChannelID: edge.ChannelID,
LastUpdate: time.Now(),
TimeLockDelta: edge.Expiry,