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

feat(rollapp): allow rollapps with no native token #1654

Merged
merged 8 commits into from
Dec 16, 2024

Conversation

mtsitrin
Copy link
Contributor

Description


Closes #XXX

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow-up issues.

PR review checkboxes:

I have...

  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Targeted PR against the correct branch
  • included the correct type prefix in the PR title
  • Linked to the GitHub issue with discussion and accepted design
  • Targets only one GitHub issue
  • Wrote unit and integration tests
  • Wrote relevant migration scripts if necessary
  • All CI checks have passed
  • Added relevant godoc comments
  • Updated the scripts for local run, e.g genesis_config_commands.sh if the PR changes parameters
  • Add an issue in the e2e-tests repo if necessary

SDK Checklist

  • Import/Export Genesis
  • Registered Invariants
  • Registered Events
  • Updated openapi.yaml
  • No usage of go map
  • No usage of time.Now()
  • Used fixed point arithmetic and not float arithmetic
  • Avoid panicking in Begin/End block as much as possible
  • No unexpected math Overflow
  • Used sendCoin and not SendCoins
  • Out-of-block compute is bounded
  • No serialized ID at the end of store keys
  • UInt to byte conversion should use BigEndian

Full security checklist here


For Reviewer:

  • Confirmed the correct type prefix in the PR title
  • Reviewers assigned
  • Confirmed all author checklist items have been addressed

After reviewer approval:

  • In case the PR targets the main branch, PR should not be squash merge in order to keep meaningful git history.
  • In case the PR targets a release branch, PR must be rebased.

@mtsitrin mtsitrin force-pushed the feat/allow_rollapp_with_no_native_token branch from 3dd0742 to 1e42c03 Compare December 15, 2024 10:40
Copy link

codecov bot commented Dec 15, 2024

Codecov Report

Attention: Patch coverage is 78.37838% with 16 lines in your changes missing coverage. Please review.

Project coverage is 22.62%. Comparing base (02cbaec) to head (1e42c03).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
x/rollapp/genesisbridge/ibc_module.go 53.84% 4 Missing and 2 partials ⚠️
x/rollapp/types/genesis_bridge_data.go 66.66% 4 Missing and 2 partials ⚠️
x/rollapp/types/genesis_info.go 89.74% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1654      +/-   ##
==========================================
+ Coverage   22.59%   22.62%   +0.02%     
==========================================
  Files         590      590              
  Lines      129299   129316      +17     
==========================================
+ Hits        29217    29254      +37     
+ Misses      96191    96176      -15     
+ Partials     3891     3886       -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mtsitrin mtsitrin marked this pull request as ready for review December 15, 2024 13:33
@mtsitrin mtsitrin requested a review from a team as a code owner December 15, 2024 13:33
return uevent.NewErrorAcknowledgement(ctx, errorsmod.Wrap(err, "genesis bridge data: to IBC denom"))
// handle rollapp's denom metadata
var raDenomOnHUb string
if genesisBridgeData.GenesisInfo.NativeDenom.IsSet() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you comment this a bit more in detail

for _, data := range genesisPackets {
if err := w.transferKeeper.OnRecvPacket(ctx, packet, data); err != nil {
return uevent.NewErrorAcknowledgement(ctx, errorsmod.Wrap(err, "handle genesis transfer"))
}
}

err = w.EnableTransfers(ctx, packet, ra, denom.Base)
err = w.EnableTransfers(ctx, packet, ra, raDenomOnHUb)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if genesisBridgeData.GenesisInfo.NativeDenom.IsSet() == false, raDenomOnHUb would be empty string, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right. as the rollapp doesn't have native denom

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just making sure that w.EnableTransfers is ok with empty string, and also the event below

x/rollapp/types/genesis_bridge_data.go Outdated Show resolved Hide resolved
@@ -33,14 +33,32 @@ func (gi GenesisInfo) GenesisTransferAmount() math.Int {
return total
}

// native denom is optional
func (gi GenesisInfo) AllSet() bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AllSet might not be an appropriate name for this method anymore, since it doesn't check NativeDenom anymore

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to Launchable

if _, exists := accountSet[a.Address]; exists {
return fmt.Errorf("duplicate genesis account: %s", a.Address)

if gi.InitialSupply.IsNil() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if InitialSupply is zero here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will fail in if total.GT(gi.InitialSupply) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you maybe leave a comment about it, just to remove doubt

Comment on lines 124 to 128
if a.Amount.IsNil() {
return fmt.Errorf("invalid amount: %s", a.Address)
}

if !a.Amount.IsPositive() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these two checks can be merged into one

Comment on lines 78 to 79
if !gi.InitialSupply.IsNil() && !gi.InitialSupply.IsZero() {
return ErrNoNativeTokenRollapp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems that the error here is not really the lack of native denom, but the fact that initial supply is non-zero while having no native tokens.

Comment on lines 82 to 83
if l := len(gi.Accounts()); l > 0 {
return ErrNoNativeTokenRollapp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above, for accounts

omritoptix
omritoptix previously approved these changes Dec 16, 2024
Copy link
Contributor

@omritoptix omritoptix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great!

} else {
// if native denom is not set, initial supply must be 0 and no accounts
if !gi.InitialSupply.IsNil() && !gi.InitialSupply.IsZero() {
return ErrNoNativeTokenRollapp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return ErrNoNativeTokenRollapp
return ErrInvalidInitialSupply

if !gi.InitialSupply.IsPositive() {
return ErrInvalidInitialSupply
if l := len(gi.Accounts()); l > 0 {
return ErrNoNativeTokenRollapp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return ErrNoNativeTokenRollapp
return ErrTooManyGenesisAccounts

x/rollapp/types/genesis_info.go Show resolved Hide resolved
Copy link
Contributor

@danwt danwt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Should document on genesis info and genesis bridge info protos that native denom can be zero type, and why
  • should doc no IRO plan possible for such rollapps

return errorsmod.Wrapf(
errors.Join(gerrc.ErrInvalidArgument, err),
"invalid genesis info",
)
}

if !m.NewGenesisInfo.AllSet() {
if !m.NewGenesisInfo.Launchable() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

launchable is somewhat misleading, since rollapp is not launchable until after. pre launch time, which is not included
needs a better docstring

Comment on lines 49 to 51
if update.GenesisInfo != nil {
if update.GenesisInfo.GenesisChecksum != "" {
current.GenesisInfo.GenesisChecksum = update.GenesisInfo.GenesisChecksum
}

if update.GenesisInfo.Bech32Prefix != "" {
current.GenesisInfo.Bech32Prefix = update.GenesisInfo.Bech32Prefix
}

if update.GenesisInfo.NativeDenom.Base != "" {
current.GenesisInfo.NativeDenom = update.GenesisInfo.NativeDenom
}

if !update.GenesisInfo.InitialSupply.IsNil() {
current.GenesisInfo.InitialSupply = update.GenesisInfo.InitialSupply
}

// Frontend always passes new value
current.GenesisInfo.GenesisAccounts = update.GenesisInfo.GenesisAccounts
current.GenesisInfo = *update.GenesisInfo
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this definitely fine?

Comment on lines 151 to 152
// It also calls the after transfers enabled hook (used to settle IRO plans)
func (w IBCModule) EnableTransfers(ctx sdk.Context, packet channeltypes.Packet, ra *types.Rollapp, rollappIBCtrace string) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should say it can be empty

Comment on lines 78 to 80
if l := len(gi.Accounts()); l > 0 {
return errorsmod.Wrap(ErrNoNativeTokenRollapp, "non empty genesis accounts")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why define l

Comment on lines +72 to 76
// if native denom is not set, initial supply must be 0 and no accounts
if !gi.NativeDenom.IsSet() {
if !gi.InitialSupply.IsNil() && !gi.InitialSupply.IsZero() {
return errorsmod.Wrap(ErrNoNativeTokenRollapp, "non zero initial supply")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't check initial supply is zero, since it can be nil

Comment on lines +117 to 119
if total.GT(gi.InitialSupply) {
return ErrInvalidInitialSupply
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not !=

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

supply != genesis bridge transfers (e.g can have 1B tokens with 1M transferred on genesis)

Comment on lines 80 to 81
// genesis info is not validated here, as we allow to update partial fields
// it will be validated when trying to apply the update
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fine grained update is removed now though

Copy link
Contributor

@danwt danwt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved,
check #1654 (comment)

@omritoptix omritoptix merged commit a9d5d6b into main Dec 16, 2024
5 checks passed
@omritoptix omritoptix deleted the feat/allow_rollapp_with_no_native_token branch December 16, 2024 11:42
omritoptix pushed a commit that referenced this pull request Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants