graph/db: update policy builders to support v2 fields
Update buildChanPolicy and related functions in both KV and SQL stores to properly construct ChannelEdgePolicy with version-specific fields: KVStore changes: - Reject non-v1 policies in updateEdgePolicy and serializeChanEdgePolicy since KV store only supports v1 gossip protocol. - Set Version to GossipVersion1 when deserializing policies from KV. SQLStore changes: - Add isNode1 parameter to buildChanPolicy functions to properly set SecondPeer field (v2 uses SecondPeer instead of ChannelFlags direction). - Extract Version from database and populate version-specific fields: - For v1: MessageFlags, ChannelFlags, LastUpdate, ExtraOpaqueData - For v2: DisableFlags, LastBlockHeight, ExtraSignedFields - Thread isNode1 through buildChanPolicyWithBatchData and buildCachedChanPolicies call sites. This enables the SQL store to read and reconstruct both v1 and v2 channel policies from the database with proper field mapping.
This commit is contained in:
3 files changed
+204
-122
No files matched your search
+10
-1
@@ -3296,6 +3296,9 @@ func updateEdgePolicy(tx kvdb.RwTx, edge *models.ChannelEdgePolicy) (
|
||||
route.Vertex, route.Vertex, bool, error) {
|
||||
|
||||
var noVertex route.Vertex
|
||||
if edge.Version != lnwire.GossipVersion1 {
|
||||
return noVertex, noVertex, false, ErrVersionNotSupportedForKVDB
|
||||
}
|
||||
|
||||
edges := tx.ReadWriteBucket(edgeBucket)
|
||||
if edges == nil {
|
||||
@@ -5226,6 +5229,10 @@ func fetchChanEdgePolicies(edgeIndex kvdb.RBucket, edges kvdb.RBucket,
|
||||
func serializeChanEdgePolicy(w io.Writer, edge *models.ChannelEdgePolicy,
|
||||
to []byte) error {
|
||||
|
||||
if edge.Version != lnwire.GossipVersion1 {
|
||||
return ErrVersionNotSupportedForKVDB
|
||||
}
|
||||
|
||||
err := wire.WriteVarBytes(w, 0, edge.SigBytes)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -5314,7 +5321,9 @@ func deserializeChanEdgePolicy(r io.Reader) (*models.ChannelEdgePolicy, error) {
|
||||
func deserializeChanEdgePolicyRaw(r io.Reader) (*models.ChannelEdgePolicy,
|
||||
error) {
|
||||
|
||||
edge := &models.ChannelEdgePolicy{}
|
||||
edge := &models.ChannelEdgePolicy{
|
||||
Version: lnwire.GossipVersion1,
|
||||
}
|
||||
|
||||
var err error
|
||||
edge.SigBytes, err = wire.ReadVarBytes(r, 0, 80, "sig")
|
||||
|
||||
Reference in new issue
Block a user