-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Deterministic connection and channel identifiers #7993
Changes from 2 commits
0462943
44174ec
e01eb98
2119731
7a1c317
38f3901
f47d238
9af89dc
36b9c66
f953238
32a1afa
005c47a
d89548a
db991d7
fb8f829
1b6bebf
fa62c83
2341f86
916b3f7
3da13bd
6818209
e671648
49d2cd7
736a139
ec8e1f2
f8c2970
2e80297
cb850b9
6024dbb
e3948d2
c3c8cd9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,17 @@ func (k Keeper) GetCommitmentPrefix() exported.Prefix { | |
return commitmenttypes.NewMerklePrefix([]byte(k.storeKey.Name())) | ||
} | ||
|
||
// GenerateConnectionIdentifier returns the next connection identifier. | ||
func (k Keeper) GenerateConnectionIdentifier(ctx sdk.Context) string { | ||
nextConnSeq := k.GetNextConnectionSequence(ctx) | ||
connectionID := fmt.Sprintf("%s%d", types.ConnectionPrefix, nextConnSeq) | ||
|
||
nextConnSeq++ | ||
k.SetNextConnectionSequence(ctx, nextConnSeq) | ||
|
||
return connectionID | ||
} | ||
|
||
// GetConnection returns a connection with a particular identifier | ||
func (k Keeper) GetConnection(ctx sdk.Context, connectionID string) (types.ConnectionEnd, bool) { | ||
store := ctx.KVStore(k.storeKey) | ||
|
@@ -105,6 +116,24 @@ func (k Keeper) SetClientConnectionPaths(ctx sdk.Context, clientID string, paths | |
store.Set(host.ClientConnectionsKey(clientID), bz) | ||
} | ||
|
||
// GetNextConnectionSequence gets the next connection sequence from the store. | ||
func (k Keeper) GetNextConnectionSequence(ctx sdk.Context) uint64 { | ||
store := ctx.KVStore(k.storeKey) | ||
bz := store.Get([]byte(types.KeyNextConnectionSequence)) | ||
if bz == nil { | ||
panic("next connection sequence is nil") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This means we didn't set it on init genesis. It is an assumption that the global counter is always set otherwise core IBC won't function properly. If it isn't set the chain should halt and fix the issue |
||
} | ||
|
||
return sdk.BigEndianToUint64(bz) | ||
} | ||
|
||
// SetNextConnectionSequence sets the next connection sequence to the store | ||
func (k Keeper) SetNextConnectionSequence(ctx sdk.Context, sequence uint64) { | ||
store := ctx.KVStore(k.storeKey) | ||
bz := sdk.Uint64ToBigEndian(sequence) | ||
store.Set([]byte(types.KeyNextConnectionSequence), bz) | ||
} | ||
|
||
// GetAllClientConnectionPaths returns all stored clients connection id paths. It | ||
// will ignore the clients that haven't initialized a connection handshake since | ||
// no paths are stored. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,12 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { | |
return ctx.Logger().With("module", fmt.Sprintf("x/%s/%s", host.ModuleName, types.SubModuleName)) | ||
} | ||
|
||
// GenerateChannelIdentifier returns the next channel identifier. | ||
func (k Keeper) GenerateConnectionIdentifier(ctx sdk.Context) string { | ||
nextChannelSeq := k.GetNextChannelSequence(ctx) | ||
return fmt.Sprintf("%s%d", types.ChannelPrefix, nextChannelSeq) | ||
} | ||
|
||
// GetChannel returns a channel with a particular identifier binded to a specific port | ||
func (k Keeper) GetChannel(ctx sdk.Context, portID, channelID string) (types.Channel, bool) { | ||
store := ctx.KVStore(k.storeKey) | ||
|
@@ -75,6 +81,24 @@ func (k Keeper) SetChannel(ctx sdk.Context, portID, channelID string, channel ty | |
store.Set(host.ChannelKey(portID, channelID), bz) | ||
} | ||
|
||
// GetNextChannelSequence gets the next channel sequence from the store. | ||
func (k Keeper) GetNextChannelSequence(ctx sdk.Context) uint64 { | ||
store := ctx.KVStore(k.storeKey) | ||
bz := store.Get([]byte(types.KeyNextChannelSequence)) | ||
if bz == nil { | ||
panic("next channel sequence is nil") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
} | ||
|
||
return sdk.BigEndianToUint64(bz) | ||
} | ||
|
||
// SetNextChannelSequence sets the next channel sequence to the store | ||
func (k Keeper) SetNextChannelSequence(ctx sdk.Context, sequence uint64) { | ||
store := ctx.KVStore(k.storeKey) | ||
bz := sdk.Uint64ToBigEndian(sequence) | ||
store.Set([]byte(types.KeyNextChannelSequence), bz) | ||
} | ||
|
||
// GetNextSequenceSend gets a channel's next send sequence from the store | ||
func (k Keeper) GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool) { | ||
store := ctx.KVStore(k.storeKey) | ||
|
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.
should we add a separator here to avoid collisions?
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.
Collisions with what? The identifier is auto derived, not user inputted