Generate local alias before spawning channel#2316
Conversation
6fc252f to
3becfb8
Compare
|
I have an alternative design for alias generation: what about inserting a new temporary channel state to generate it? Whenever we currently call |
|
Something else that comes to mind: for public channels that aren't using 0-conf (which is going to be the most common flow for most node operators), we probably shouldn't really generate a |
I thought about that, but I'd don't like adding new states because we then need to handle all the other events (remote errors, funding spent, disconnection, etc.) and it quickly becomes bulky.
That's a good point, but I think we don't want to have duplicate aliases, it should be an |
|
Yes, it's true, after thinking about it more I think we should keep the |
| * .as[MyClass] | ||
| * }}} | ||
| */ | ||
| object Mutators { |
There was a problem hiding this comment.
Should we put that in a versioned namespace (this one would go in the version3 package since we introduced the need for it in version3 and won't need it for future versions)?
There was a problem hiding this comment.
Maybe, although we sort of adopted the opposite approach for ChannelTypes0.
There was a problem hiding this comment.
On the contrary, we put ChannelTypes0 in the version1 package? But it doesn't matter right now, we can move those mutators to a versioned package when we introduce new ones that are for a different codecs version.
Using the first 7B increases the risk of collision at migration due to how `channel_id` is built. Collisions would happen when multiple channels are funded with the same transaction.
| val localAlias_p = Promise[Alias]() | ||
| context.system.eventStream.publish(Register.GenerateLocalAlias(localAlias_p)) |
There was a problem hiding this comment.
This isn't very academic, but:
- using the
eventStreamsaves us from having to pass a reference toregisterall the way to thepeer - using a
Promisesaves us from creating an ad-hoc actor (pipeTodoesn't work with theeventStreamapproach)
| // at block height 1000 LN didn't exist, so all real scids less than that will never be used | ||
| val upperBound = RealShortChannelId.apply(BlockHeight(1000),1,0).toLong |
There was a problem hiding this comment.
Why do we use such a small range? We can go up to at least block 350 000, can't we?
There was a problem hiding this comment.
The space is already huge : 1_099_511_627_841_536 (*) and we are checking for duplicates. I figure leaving some values available could prove handy later?
(*) So huge in fact that I believe our previous computation was invalid. If we indeed go up to block height 350 000 it gives us a ceiling of 384_829_069_721_665_536 which is about 2^59. The probability of a collision for 250 000 channels would be 0.000011 %, not 0.8 % ?
| def generateLocalAlias(): Alias = { | ||
| // at block height 1000 LN didn't exist, so all real scids less than that will never be used | ||
| val upperBound = RealShortChannelId.apply(BlockHeight(1000),1,0).toLong | ||
| Alias(Random.nextLong(upperBound)) |
There was a problem hiding this comment.
We should use the randomLong from package.scala here.
| * .as[MyClass] | ||
| * }}} | ||
| */ | ||
| object Mutators { |
There was a problem hiding this comment.
On the contrary, we put ChannelTypes0 in the version1 package? But it doesn't matter right now, we can move those mutators to a versioned package when we introduce new ones that are for a different codecs version.
| case None => compatReplyTo ! ForwardShortIdFailure(fwd) | ||
| } | ||
|
|
||
| case GenerateLocalAlias(promise) => |
There was a problem hiding this comment.
Since we re-populate the shortIds map asynchronously as channels are restored and send ShortChannelIdAssigned, we may receive that message before we've restored all channels and recovered a complete shortIds map.
I believe it won't be an issue in practice as long as the range we use for ShortChannelId.generateLocalAlias() is big enough to make collisions unlikely.
| system.eventStream.subscribe(generateLocalAliasListener.ref, classOf[GenerateLocalAlias]) | ||
| waitEventStreamSynced(system.eventStream) | ||
| generateLocalAliasListener.setAutoPilot { | ||
| case (_, gen:GenerateLocalAlias) => |
There was a problem hiding this comment.
nit:
| case (_, gen:GenerateLocalAlias) => | |
| case (_, gen: GenerateLocalAlias) => |
|
Superseded by #2337. |
As a first step before addressing #2224 (comment), we need to make the alias generation asynchronous.
Peer generates the alias along with the shutdown script, and before spawning the channel.
This approach has several drawbacks:
WAIT_FOR_FUNDING_CONFIRMED, which is persisted and requires a migration. We can't set it to the real scid because we don't have it yet