-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[3/7] multi: start using the new interfaces throughout the codebase #8252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: elle-g175ChanDBUpdates
Are you sure you want to change the base?
[3/7] multi: start using the new interfaces throughout the codebase #8252
Conversation
9f01c45
to
73b8186
Compare
be56e6f
to
2d9ef0c
Compare
73b8186
to
e6ea852
Compare
Important Review skippedAuto reviews are limited to specific labels. Labels to auto review (1)
Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
In preparation for CachedEdgePolicy being used to represent ChannelEdgePolicy1 or ChannelEdgePolicy2, we update it to have IsDisabled and HasMaxHTLC booleans (which can be extracted from both messages) instead of having the MessageFlags and ChannelFlags which only applies to ChannelEdgePolicy1.
Update the graph cache to use the new ChannelEdgePolicy and ChannelEdgeInfo interfaces where possible.
Add a new ChannelUpdate2 message which can be returned with a Failure. Also add a block_height member to the RoutingPolicy which will be populated when the last_update field is not.
2d9ef0c
to
12d2106
Compare
b1baa7d
to
f05fe47
Compare
f05fe47
to
fea428d
Compare
if err != nil { | ||
return | ||
|
||
// TODO(elle): Add inbound fees field to ChannelEdgePolicy2 & |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so. This came up in the spec meeting a few weeks ago, and it's the prefect location imo:
- Doing positive fees needs all senders to update.
- In order to use the new gossip protocol, the sender will need to have updated to be able to validate the channels.
- Therefore, the new gossip protocol is a great place to add inbound fees "officially".
We can use a tlv.OptionaRecordT
here.
@@ -4878,6 +4883,83 @@ message ChannelUpdate { | |||
bytes extra_opaque_data = 12; | |||
} | |||
|
|||
message ChannelUpdate2 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given all the data is pretty much the same, do we actually need to make an entirely new proto?
One consideration is the signature
field, but in that case, we can add a new enum to indicate which channel update type was encoded.
// construct the pk script from the announcement, and so we | ||
// instead need to fetch the pk script. | ||
if a.BitcoinKey1.IsNone() && a.BitcoinKey2.IsNone() { | ||
pkScript, err := d.fetchPKScript(&a.ShortChannelID.Val) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC previously this was done at the router level, given that's where the on chain validation actually occurs.
@@ -41,9 +43,47 @@ func (f rejectFlags) unpack() (bool, bool) { | |||
// including the timestamps of its latest edge policies and whether or not the | |||
// channel exists in the graph. | |||
type rejectCacheEntry struct { | |||
times *updateTimes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we should actually just split the caches into two? Given that in the future, we may have two announcements for any given channel.
return err | ||
} | ||
} | ||
|
||
if err := updateIndex.Put(indexKey[:], nil); err != nil { | ||
if err := updateIndex.Put(indexKey, nil); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should consider splitting this bucket structure.
We commonly use this index to implement an in-order to send out updates ordered by timestamp to a peer:
Lines 1922 to 1948 in 13a7bec
edgeUpdateIndex := edges.NestedReadBucket(edgeUpdateIndexBucket) | |
if edgeUpdateIndex == nil { | |
return ErrGraphNoEdgesFound | |
} | |
nodes := tx.ReadBucket(nodeBucket) | |
if nodes == nil { | |
return ErrGraphNodesNotFound | |
} | |
// We'll now obtain a cursor to perform a range query within | |
// the index to find all channels within the horizon. | |
updateCursor := edgeUpdateIndex.ReadCursor() | |
var startTimeBytes, endTimeBytes [8 + 8]byte | |
byteOrder.PutUint64( | |
startTimeBytes[:8], uint64(startTime.Unix()), | |
) | |
byteOrder.PutUint64( | |
endTimeBytes[:8], uint64(endTime.Unix()), | |
) | |
// With our start and end times constructed, we'll step through | |
// the index collecting the info and policy of each update of | |
// each channel that has a last update within the time range. | |
for indexKey, _ := updateCursor.Seek(startTimeBytes[:]); indexKey != nil && | |
bytes.Compare(indexKey, endTimeBytes[:]) <= 0; indexKey, _ = updateCursor.Next() { |
If we overload the key in this structure, then the ordering is inherently broken, and then requires extra logic to skip over those new entries for a peer that only understands the legacy update type.
Assuming that the desired behavior for an updated peer is to send both edge types, coalescing the block based and timestamp based, then we can implement a composite cursor/iterator (using slow/fast pointers) to create a consistently ordered response.
// timestamps. | ||
// | ||
// maps: blockHeight || chanID -> nil | ||
edgeUpdate2IndexBucket = []byte("edge-update-2-index") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah scratch my other comment, it was partitioned after all!
}, nil | ||
|
||
case *models.ChannelEdgePolicy2: | ||
indexKey := make([]byte, 4+8) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need the block height and the scid value? The scid encodes a block height (unrolled)
@@ -1157,13 +1157,84 @@ func (c *ChannelGraph) addChannelEdge(tx kvdb.RwTx, | |||
return chanIndex.Put(b.Bytes(), chanKey[:]) | |||
} | |||
|
|||
// HasChannelEdge returns true if the database knows of a channel edge with the | |||
func (c *ChannelGraph) HasChannelEdge(chanID uint64) (bool, bool, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
godoc
comment was lost in the update.
// We'll query the cache with the shared lock held to allow multiple | ||
// readers to access values in the cache concurrently if they exist. | ||
c.cacheMu.RLock() | ||
if entry, ok := c.rejectCache.get(chanID); ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this entire method is a dup.
@@ -1279,6 +1350,122 @@ func (c *ChannelGraph) HasChannelEdge( | |||
return upd1Time, upd2Time, exists, isZombie, nil | |||
} | |||
|
|||
func (c *ChannelGraph) HasChannelEdge2( | |||
chanID uint64) (uint32, uint32, bool, bool, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think time for a return value struct given we have 5 return values here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also these two methods look pretty much identical (just height vs time stamps). Minimally, we can refactor some of the duplicate inner logic into a new function. Going a step further: can we abstract away the height vs timestamp difference? So something like a UpdateOrder
?
This is part of the Gossip 1.75 epic.
Depends on #8164 so only the last 10 commits are new
In this PR, we start threading the new interfaces throughout the code base. This threading
process has been split up into 3 PRs. This one covers the following major changes:
routing.Validate
to validate the new Channel Announcementchanneldb.GraphCache
use the new interfaces where possibleChannelEdgeInfo
interface throughoutHasChannelPolicy
accordingly