Skip to content
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

chore: update adr 001 #7783

Open
wants to merge 1 commit into
base: feat/ibc-eureka
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 30 additions & 30 deletions docs/architecture/adr-001-coin-source-tracing.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ The new proposed format will be the following:
ibcDenom = "ibc/" + hash(trace path + "/" + base denom)
```

The hash function will be a SHA256 hash of the fields of the `DenomTrace`:
The hash function will be a SHA256 hash of the fields of the `Denom`:

```protobuf
// DenomTrace contains the base denomination for ICS20 fungible tokens and the source tracing
// Denom contains the base denomination for ICS20 fungible tokens and the source tracing
// information
message DenomTrace {
message Denom {
// chain of port/channel identifiers used for tracing the source of the fungible token
string path = 1;
// base denomination of the relayed fungible token
Expand All @@ -134,16 +134,16 @@ message DenomTrace {
The `IBCDenom` function constructs the `Coin` denomination used when creating the ICS20 fungible token packet data:

```go
// Hash returns the hex bytes of the SHA256 hash of the DenomTrace fields using the following formula:
// Hash returns the hex bytes of the SHA256 hash of the Denom fields using the following formula:
//
// hash = sha256(tracePath + "/" + baseDenom)
func (dt DenomTrace) Hash() tmbytes.HexBytes {
func (dt Denom) Hash() tmbytes.HexBytes {
return tmhash.Sum(dt.Path + "/" + dt.BaseDenom)
}

// IBCDenom a coin denomination for an ICS20 fungible token in the format 'ibc/{hash(tracePath + baseDenom)}'.
// If the trace is empty, it will return the base denomination.
func (dt DenomTrace) IBCDenom() string {
func (dt Denom) IBCDenom() string {
if dt.Path != "" {
return fmt.Sprintf("ibc/%s", dt.Hash())
}
Expand All @@ -155,33 +155,33 @@ func (dt DenomTrace) IBCDenom() string {

In order to retrieve the trace information from an IBC denomination, a lookup table needs to be
added to the `ibc-transfer` module. These values need to also be persisted between upgrades, meaning
that a new `[]DenomTrace` `GenesisState` field state needs to be added to the module:
that a new `[]Denom` `GenesisState` field state needs to be added to the module:

```go
// GetDenomTrace retrieves the full identifiers trace and base denomination from the store.
func (k Keeper) GetDenomTrace(ctx Context, denomTraceHash []byte) (DenomTrace, bool) {
// GetDenom retrieves the full identifiers trace and base denomination from the store.
func (k Keeper) GetDenom(ctx Context, denomHash []byte) (Denom, bool) {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.KeyDenomTrace(traceHash))
bz := store.Get(types.KeyDenom(traceHash))
if bz == nil {
return &DenomTrace, false
return &Denom, false
}

var denomTrace DenomTrace
k.cdc.MustUnmarshalBinaryBare(bz, &denomTrace)
return denomTrace, true
var denom Denom
k.cdc.MustUnmarshalBinaryBare(bz, &denom)
return denom, true
}

// HasDenomTrace checks if a the key with the given trace hash exists on the store.
func (k Keeper) HasDenomTrace(ctx Context, denomTraceHash []byte) bool {
// HasDenom checks if a the key with the given trace hash exists on the store.
func (k Keeper) HasDenom(ctx Context, denomHash []byte) bool {
store := ctx.KVStore(k.storeKey)
return store.Has(types.KeyTrace(denomTraceHash))
return store.Has(types.KeyTrace(denomHash))
}

// SetDenomTrace sets a new {trace hash -> trace} pair to the store.
func (k Keeper) SetDenomTrace(ctx Context, denomTrace DenomTrace) {
// SetDenom sets a new {trace hash -> trace} pair to the store.
func (k Keeper) SetDenom(ctx Context, denom Denom) {
store := ctx.KVStore(k.storeKey)
bz := k.cdc.MustMarshalBinaryBare(&denomTrace)
store.Set(types.KeyTrace(denomTrace.Hash()), bz)
bz := k.cdc.MustMarshalBinaryBare(&denom)
store.Set(types.KeyTrace(denom.Hash()), bz)
}
```

Expand Down Expand Up @@ -255,12 +255,12 @@ func (k Keeper) DenomPathFromHash(ctx sdk.Context, denom string) (string, error)
return "", Wrap(ErrInvalidDenomForTransfer, err.Error())
}

denomTrace, found := k.GetDenomTrace(ctx, hash)
denom, found := k.GetDenom(ctx, hash)
if !found {
return "", Wrap(ErrTraceNotFound, hexHash)
}

fullDenomPath := denomTrace.GetFullDenomPath()
fullDenomPath := denom.GetFullDenomPath()
return fullDenomPath, nil
}
```
Expand Down Expand Up @@ -297,15 +297,15 @@ sourcePrefix := types.GetDenomPrefix(packet.GetDestPort(), packet.GetDestChannel
prefixedDenom := sourcePrefix + data.Denom

// construct the denomination trace from the full raw denomination
denomTrace := types.ParseDenomTrace(prefixedDenom)
denom := types.ParseDenom(prefixedDenom)

// set the value to the lookup table if not stored already
traceHash := denomTrace.Hash()
if !k.HasDenomTrace(ctx, traceHash) {
k.SetDenomTrace(ctx, traceHash, denomTrace)
traceHash := denom.Hash()
if !k.HasDenom(ctx, traceHash) {
k.SetDenom(ctx, traceHash, denom)
}

voucherDenom := denomTrace.IBCDenom()
voucherDenom := denom.IBCDenom()
voucher := sdk.NewCoin(voucherDenom, sdk.NewIntFromUint64(data.Amount))

// mint new tokens if the source of the transfer is the same chain
Expand All @@ -322,13 +322,13 @@ return k.bankKeeper.SendCoinsFromModuleToAccount(
```

```go
func NewDenomTraceFromRawDenom(denom string) DenomTrace{
func NewDenomFromRawDenom(denom string) Denom{
denomSplit := strings.Split(denom, "/")
trace := ""
if len(denomSplit) > 1 {
trace = strings.Join(denomSplit[:len(denomSplit)-1], "/")
}
return DenomTrace{
return Denom{
BaseDenom: denomSplit[len(denomSplit)-1],
Trace: trace,
}
Expand Down
Loading