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:
parent
2105a06a26
commit
19174ebdfd
@ -1108,6 +1108,10 @@ func (p *ChannelAuthProof) IsEmpty() bool {
|
|||||||
// information concerning fees, and minimum time-lock information which is
|
// information concerning fees, and minimum time-lock information which is
|
||||||
// utilized during path finding.
|
// utilized during path finding.
|
||||||
type ChannelEdgePolicy struct {
|
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
|
// 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,
|
// 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.
|
// 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())
|
return nodeBucket.Put(nodePub, b.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1462,6 +1471,16 @@ func deserializeLightningNode(r io.Reader) (*LightningNode, error) {
|
|||||||
}
|
}
|
||||||
node.Addresses = addresses
|
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
|
return node, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1626,6 +1645,11 @@ func putChanEdgePolicy(edges *bolt.Bucket, edge *ChannelEdgePolicy, from, to []b
|
|||||||
|
|
||||||
var b bytes.Buffer
|
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 {
|
if err := binary.Write(&b, byteOrder, edge.ChannelID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -1723,6 +1747,16 @@ func deserializeChanEdgePolicy(r io.Reader,
|
|||||||
|
|
||||||
edge := &ChannelEdgePolicy{}
|
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 {
|
if err := binary.Read(r, byteOrder, &edge.ChannelID); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,7 @@ func createTestVertex(db *DB) (*LightningNode, error) {
|
|||||||
|
|
||||||
pub := priv.PubKey().SerializeCompressed()
|
pub := priv.PubKey().SerializeCompressed()
|
||||||
return &LightningNode{
|
return &LightningNode{
|
||||||
|
AuthSig: testSig,
|
||||||
LastUpdate: time.Unix(updateTime, 0),
|
LastUpdate: time.Unix(updateTime, 0),
|
||||||
PubKey: priv.PubKey(),
|
PubKey: priv.PubKey(),
|
||||||
Color: color.RGBA{1, 2, 3, 0},
|
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.
|
// graph, so we'll create a test vertex to start with.
|
||||||
_, testPub := btcec.PrivKeyFromBytes(btcec.S256(), key[:])
|
_, testPub := btcec.PrivKeyFromBytes(btcec.S256(), key[:])
|
||||||
node := &LightningNode{
|
node := &LightningNode{
|
||||||
|
AuthSig: testSig,
|
||||||
LastUpdate: time.Unix(1232342, 0),
|
LastUpdate: time.Unix(1232342, 0),
|
||||||
PubKey: testPub,
|
PubKey: testPub,
|
||||||
Color: color.RGBA{1, 2, 3, 0},
|
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
|
// With the edge added, we can now create some fake edge information to
|
||||||
// update for both edges.
|
// update for both edges.
|
||||||
edge1 := &ChannelEdgePolicy{
|
edge1 := &ChannelEdgePolicy{
|
||||||
|
Signature: testSig,
|
||||||
ChannelID: chanID,
|
ChannelID: chanID,
|
||||||
LastUpdate: time.Unix(433453, 0),
|
LastUpdate: time.Unix(433453, 0),
|
||||||
Flags: 0,
|
Flags: 0,
|
||||||
@ -411,6 +414,7 @@ func TestEdgeInfoUpdates(t *testing.T) {
|
|||||||
db: db,
|
db: db,
|
||||||
}
|
}
|
||||||
edge2 := &ChannelEdgePolicy{
|
edge2 := &ChannelEdgePolicy{
|
||||||
|
Signature: testSig,
|
||||||
ChannelID: chanID,
|
ChannelID: chanID,
|
||||||
LastUpdate: time.Unix(124234, 0),
|
LastUpdate: time.Unix(124234, 0),
|
||||||
Flags: 1,
|
Flags: 1,
|
||||||
@ -589,6 +593,7 @@ func TestGraphTraversal(t *testing.T) {
|
|||||||
edge := randEdgePolicy(chanID, op, db)
|
edge := randEdgePolicy(chanID, op, db)
|
||||||
edge.Flags = 0
|
edge.Flags = 0
|
||||||
edge.Node = secondNode
|
edge.Node = secondNode
|
||||||
|
edge.Signature = testSig
|
||||||
if err := graph.UpdateEdgePolicy(edge); err != nil {
|
if err := graph.UpdateEdgePolicy(edge); err != nil {
|
||||||
t.Fatalf("unable to update edge: %v", err)
|
t.Fatalf("unable to update edge: %v", err)
|
||||||
}
|
}
|
||||||
@ -598,6 +603,7 @@ func TestGraphTraversal(t *testing.T) {
|
|||||||
edge = randEdgePolicy(chanID, op, db)
|
edge = randEdgePolicy(chanID, op, db)
|
||||||
edge.Flags = 1
|
edge.Flags = 1
|
||||||
edge.Node = firstNode
|
edge.Node = firstNode
|
||||||
|
edge.Signature = testSig
|
||||||
if err := graph.UpdateEdgePolicy(edge); err != nil {
|
if err := graph.UpdateEdgePolicy(edge); err != nil {
|
||||||
t.Fatalf("unable to update edge: %v", err)
|
t.Fatalf("unable to update edge: %v", err)
|
||||||
}
|
}
|
||||||
@ -743,6 +749,7 @@ func TestGraphPruning(t *testing.T) {
|
|||||||
edge := randEdgePolicy(chanID, op, db)
|
edge := randEdgePolicy(chanID, op, db)
|
||||||
edge.Flags = 0
|
edge.Flags = 0
|
||||||
edge.Node = graphNodes[i]
|
edge.Node = graphNodes[i]
|
||||||
|
edge.Signature = testSig
|
||||||
if err := graph.UpdateEdgePolicy(edge); err != nil {
|
if err := graph.UpdateEdgePolicy(edge); err != nil {
|
||||||
t.Fatalf("unable to update edge: %v", err)
|
t.Fatalf("unable to update edge: %v", err)
|
||||||
}
|
}
|
||||||
@ -752,6 +759,7 @@ func TestGraphPruning(t *testing.T) {
|
|||||||
edge = randEdgePolicy(chanID, op, db)
|
edge = randEdgePolicy(chanID, op, db)
|
||||||
edge.Flags = 1
|
edge.Flags = 1
|
||||||
edge.Node = graphNodes[i]
|
edge.Node = graphNodes[i]
|
||||||
|
edge.Signature = testSig
|
||||||
if err := graph.UpdateEdgePolicy(edge); err != nil {
|
if err := graph.UpdateEdgePolicy(edge); err != nil {
|
||||||
t.Fatalf("unable to update edge: %v", err)
|
t.Fatalf("unable to update edge: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,7 @@ func createGraphNode() (*channeldb.LightningNode, error) {
|
|||||||
PubKey: priv.PubKey(),
|
PubKey: priv.PubKey(),
|
||||||
Color: color.RGBA{1, 2, 3, 0},
|
Color: color.RGBA{1, 2, 3, 0},
|
||||||
Alias: "kek" + string(pub[:]),
|
Alias: "kek" + string(pub[:]),
|
||||||
|
AuthSig: testSig,
|
||||||
Features: testFeatures,
|
Features: testFeatures,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
@ -79,6 +80,7 @@ func randEdgePolicy(chanID lnwire.ShortChannelID,
|
|||||||
node *channeldb.LightningNode) *channeldb.ChannelEdgePolicy {
|
node *channeldb.LightningNode) *channeldb.ChannelEdgePolicy {
|
||||||
|
|
||||||
return &channeldb.ChannelEdgePolicy{
|
return &channeldb.ChannelEdgePolicy{
|
||||||
|
Signature: testSig,
|
||||||
ChannelID: chanID.ToUint64(),
|
ChannelID: chanID.ToUint64(),
|
||||||
LastUpdate: time.Unix(int64(prand.Int31()), 0),
|
LastUpdate: time.Unix(int64(prand.Int31()), 0),
|
||||||
TimeLockDelta: uint16(prand.Int63()),
|
TimeLockDelta: uint16(prand.Int63()),
|
||||||
|
@ -163,6 +163,7 @@ func parseTestGraph(path string) (*channeldb.ChannelGraph, func(), aliasMap, err
|
|||||||
}
|
}
|
||||||
|
|
||||||
dbNode := &channeldb.LightningNode{
|
dbNode := &channeldb.LightningNode{
|
||||||
|
AuthSig: testSig,
|
||||||
LastUpdate: time.Now(),
|
LastUpdate: time.Now(),
|
||||||
Addresses: testAddrs,
|
Addresses: testAddrs,
|
||||||
PubKey: pub,
|
PubKey: pub,
|
||||||
@ -257,6 +258,7 @@ func parseTestGraph(path string) (*channeldb.ChannelGraph, func(), aliasMap, err
|
|||||||
}
|
}
|
||||||
|
|
||||||
edgePolicy := &channeldb.ChannelEdgePolicy{
|
edgePolicy := &channeldb.ChannelEdgePolicy{
|
||||||
|
Signature: testSig,
|
||||||
ChannelID: edge.ChannelID,
|
ChannelID: edge.ChannelID,
|
||||||
LastUpdate: time.Now(),
|
LastUpdate: time.Now(),
|
||||||
TimeLockDelta: edge.Expiry,
|
TimeLockDelta: edge.Expiry,
|
||||||
|
Loading…
Reference in New Issue
Block a user