Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
fish-sammy committed Sep 10, 2024
1 parent ca2e882 commit a81f3d3
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 30 deletions.
2 changes: 1 addition & 1 deletion x/nexus/keeper/general_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func getProcessingMessageKey(destinationChain exported.ChainName, id string) key
// GenerateMessageID generates a unique general message ID, and returns the message ID, current transacation ID and a unique integer nonce
// The message ID is just a concatenation of the transaction ID and the nonce
func (k Keeper) GenerateMessageID(ctx sdk.Context) (string, []byte, uint64) {
hash, nonce := k.NextID(ctx)
hash, nonce := k.nextID(ctx)

return fmt.Sprintf("0x%s-%d", hex.EncodeToString(hash[:]), nonce), hash[:], nonce
}
Expand Down
9 changes: 7 additions & 2 deletions x/nexus/keeper/msg_id_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ func getTxHash(ctx sdk.Context) [32]byte {
return sha256.Sum256(ctx.TxBytes())
}

// NextID returns the transaction hash of the current transaction and the incremented nonce
func (k Keeper) NextID(ctx sdk.Context) ([32]byte, uint64) {
// IncrID increments the nonce
func (k Keeper) IncrID(ctx sdk.Context) {
utils.NewCounter[uint64](messageNonceKey, k.getStore(ctx)).Incr(ctx)

Check warning on line 20 in x/nexus/keeper/msg_id_generator.go

View check run for this annotation

Codecov / codecov/patch

x/nexus/keeper/msg_id_generator.go#L19-L20

Added lines #L19 - L20 were not covered by tests
}

// nextID returns the transaction hash of the current transaction and the incremented nonce
func (k Keeper) nextID(ctx sdk.Context) ([32]byte, uint64) {
return getTxHash(ctx), utils.NewCounter[uint64](messageNonceKey, k.getStore(ctx)).Incr(ctx)
}

Expand Down
10 changes: 5 additions & 5 deletions x/nexus/keeper/wasmer_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (w *WasmerEngine) Instantiate(
gasLimit uint64,
deserCost wasmvmtypes.UFraction,
) (*wasmvmtypes.Response, uint64, error) {
defer w.msgIDGenerator.NextID(getCtx(querier))
defer w.msgIDGenerator.IncrID(getCtx(querier))

Check warning on line 41 in x/nexus/keeper/wasmer_engine.go

View check run for this annotation

Codecov / codecov/patch

x/nexus/keeper/wasmer_engine.go#L40-L41

Added lines #L40 - L41 were not covered by tests

return w.WasmerEngine.Instantiate(checksum, env, info, initMsg, store, goapi, querier, gasMeter, gasLimit, deserCost)

Check warning on line 43 in x/nexus/keeper/wasmer_engine.go

View check run for this annotation

Codecov / codecov/patch

x/nexus/keeper/wasmer_engine.go#L43

Added line #L43 was not covered by tests
}
Expand All @@ -56,7 +56,7 @@ func (w *WasmerEngine) Execute(
gasLimit uint64,
deserCost wasmvmtypes.UFraction,
) (*wasmvmtypes.Response, uint64, error) {
defer w.msgIDGenerator.NextID(getCtx(querier))
defer w.msgIDGenerator.IncrID(getCtx(querier))

Check warning on line 59 in x/nexus/keeper/wasmer_engine.go

View check run for this annotation

Codecov / codecov/patch

x/nexus/keeper/wasmer_engine.go#L58-L59

Added lines #L58 - L59 were not covered by tests

return w.WasmerEngine.Execute(code, env, info, executeMsg, store, goapi, querier, gasMeter, gasLimit, deserCost)

Check warning on line 61 in x/nexus/keeper/wasmer_engine.go

View check run for this annotation

Codecov / codecov/patch

x/nexus/keeper/wasmer_engine.go#L61

Added line #L61 was not covered by tests
}
Expand All @@ -73,7 +73,7 @@ func (w *WasmerEngine) Migrate(
gasLimit uint64,
deserCost wasmvmtypes.UFraction,
) (*wasmvmtypes.Response, uint64, error) {
defer w.msgIDGenerator.NextID(getCtx(querier))
defer w.msgIDGenerator.IncrID(getCtx(querier))

Check warning on line 76 in x/nexus/keeper/wasmer_engine.go

View check run for this annotation

Codecov / codecov/patch

x/nexus/keeper/wasmer_engine.go#L75-L76

Added lines #L75 - L76 were not covered by tests

return w.WasmerEngine.Migrate(checksum, env, migrateMsg, store, goapi, querier, gasMeter, gasLimit, deserCost)

Check warning on line 78 in x/nexus/keeper/wasmer_engine.go

View check run for this annotation

Codecov / codecov/patch

x/nexus/keeper/wasmer_engine.go#L78

Added line #L78 was not covered by tests
}
Expand All @@ -90,7 +90,7 @@ func (w *WasmerEngine) Sudo(
gasLimit uint64,
deserCost wasmvmtypes.UFraction,
) (*wasmvmtypes.Response, uint64, error) {
defer w.msgIDGenerator.NextID(getCtx(querier))
defer w.msgIDGenerator.IncrID(getCtx(querier))

Check warning on line 93 in x/nexus/keeper/wasmer_engine.go

View check run for this annotation

Codecov / codecov/patch

x/nexus/keeper/wasmer_engine.go#L92-L93

Added lines #L92 - L93 were not covered by tests

return w.WasmerEngine.Sudo(checksum, env, sudoMsg, store, goapi, querier, gasMeter, gasLimit, deserCost)

Check warning on line 95 in x/nexus/keeper/wasmer_engine.go

View check run for this annotation

Codecov / codecov/patch

x/nexus/keeper/wasmer_engine.go#L95

Added line #L95 was not covered by tests
}
Expand All @@ -107,7 +107,7 @@ func (w *WasmerEngine) Reply(
gasLimit uint64,
deserCost wasmvmtypes.UFraction,
) (*wasmvmtypes.Response, uint64, error) {
defer w.msgIDGenerator.NextID(getCtx(querier))
defer w.msgIDGenerator.IncrID(getCtx(querier))

Check warning on line 110 in x/nexus/keeper/wasmer_engine.go

View check run for this annotation

Codecov / codecov/patch

x/nexus/keeper/wasmer_engine.go#L109-L110

Added lines #L109 - L110 were not covered by tests

return w.WasmerEngine.Reply(checksum, env, reply, store, goapi, querier, gasMeter, gasLimit, deserCost)

Check warning on line 112 in x/nexus/keeper/wasmer_engine.go

View check run for this annotation

Codecov / codecov/patch

x/nexus/keeper/wasmer_engine.go#L112

Added line #L112 was not covered by tests
}
2 changes: 1 addition & 1 deletion x/nexus/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type Nexus interface {

// MsgIDGenerator provides functionality to generate msg IDs
type MsgIDGenerator interface {
NextID(ctx sdk.Context) ([32]byte, uint64)
IncrID(ctx sdk.Context)
CurrID(ctx sdk.Context) ([32]byte, uint64)
}

Expand Down
42 changes: 21 additions & 21 deletions x/nexus/types/mock/expected_keepers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a81f3d3

Please sign in to comment.