-
Notifications
You must be signed in to change notification settings - Fork 54
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 (l2): hard fork #591
Open
faultytolly
wants to merge
18
commits into
main
Choose a base branch
from
tip/rdk_hardfork
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,056
−52
Open
feat (l2): hard fork #591
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
423dc71
rdk hard fork
6a95042
include NewDRS
d973af8
message upgrade DRS
783f2cc
checkpoint
d79fa79
all works
ecce551
add msgbumpaccountsequence tests
fa0ab52
temp
c0a18dc
fix
c7696a2
add upgrade handler
a113552
Merge remote-tracking branch 'origin/main' into tip/rdk_hardfork
8c5834c
add more tests
2f1d4a3
Merge branch 'tip/rdk_hardfork' of github.com-faulty:dymensionxyz/dym…
d932c11
lint
19e677b
Merge remote-tracking branch 'origin/tip/rdk_hardfork' into tip/rdk_h…
029cb8b
block height at actual height
14691a7
upgrade sequence bump value
866ce1a
update drs only when drs is different
a1bb7b1
Merge branch 'main' into tip/rdk_hardfork
mtsitrin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,17 @@ | |
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" | ||
|
||
errorsmod "cosmossdk.io/errors" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" | ||
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" | ||
"github.com/dymensionxyz/gerr-cosmos/gerrc" | ||
"github.com/gogo/protobuf/proto" | ||
|
||
"github.com/dymensionxyz/dymension-rdk/utils/uevent" | ||
"github.com/dymensionxyz/dymension-rdk/x/sequencers/types" | ||
|
@@ -113,3 +118,97 @@ | |
|
||
return &types.ConsensusMsgUpsertSequencerResponse{}, nil | ||
} | ||
|
||
// defines the list of accounts we want to bump the sequence | ||
var handleAccounts = map[string]struct{}{ | ||
proto.MessageName(&authtypes.BaseAccount{}): {}, | ||
proto.MessageName(&vestingtypes.BaseVestingAccount{}): {}, | ||
proto.MessageName(&vestingtypes.ContinuousVestingAccount{}): {}, | ||
proto.MessageName(&vestingtypes.DelayedVestingAccount{}): {}, | ||
proto.MessageName(&vestingtypes.PeriodicVestingAccount{}): {}, | ||
proto.MessageName(&vestingtypes.PermanentLockedAccount{}): {}, | ||
} | ||
|
||
const BumpSequence = 10_000_000_000 | ||
|
||
func (m msgServer) BumpAccountSequences(goCtx context.Context, msg *types.MsgBumpAccountSequences) (*types.MsgBumpAccountSequencesResponse, error) { | ||
if msg.Authority != m.authority { | ||
return nil, sdkerrors.ErrorInvalidSigner.Wrapf("only an authorized actor can bump account sequences") | ||
} | ||
|
||
ctx := sdk.UnwrapSDKContext(goCtx) | ||
|
||
var allErrors error | ||
m.accountKeeper.IterateAccounts(ctx, func(account authtypes.AccountI) bool { | ||
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 u not breaking with error on the first error? |
||
// handle well known accounts | ||
accType := proto.MessageName(account) | ||
_, toHandle := handleAccounts[accType] | ||
if toHandle { | ||
err := m.bumpAccountSequence(ctx, account) | ||
allErrors = errors.Join(allErrors, err) | ||
} else { | ||
// check if it can be handled by something custom | ||
for _, f := range m.accountBumpFilters { | ||
toBump, err := f(accType, account) | ||
if err != nil { | ||
allErrors = errors.Join(allErrors, fmt.Errorf("filter account: %w", err)) | ||
return false | ||
} | ||
if toBump { | ||
err := m.bumpAccountSequence(ctx, account) | ||
allErrors = errors.Join(allErrors, err) | ||
break | ||
} | ||
Comment on lines
+147
to
+161
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. Can refac to only call bump once |
||
} | ||
} | ||
return false | ||
}) | ||
|
||
// we could decide to stop or continue | ||
return &types.MsgBumpAccountSequencesResponse{}, allErrors | ||
} | ||
|
||
func (m msgServer) bumpAccountSequence(ctx sdk.Context, acc authtypes.AccountI) error { | ||
err := acc.SetSequence(acc.GetSequence() + BumpSequence) | ||
if err != nil { | ||
return fmt.Errorf("set account sequence: %w", err) | ||
} | ||
m.accountKeeper.SetAccount(ctx, acc) | ||
return nil | ||
} | ||
|
||
func (m msgServer) UpgradeDRS(goCtx context.Context, drs *types.MsgUpgradeDRS) (*types.MsgUpgradeDRSResponse, error) { | ||
ctx := sdk.UnwrapSDKContext(goCtx) | ||
|
||
needUpgrade := m.updateDrsVersion(ctx, drs.DrsVersion) | ||
|
||
if needUpgrade { | ||
err := m.upgradeKeeper.ScheduleUpgrade(ctx, upgradetypes.Plan{ | ||
Name: fmt.Sprintf("upgrade-drs-%d", drs.DrsVersion), | ||
Height: ctx.BlockHeight(), | ||
Info: fmt.Sprintf("upgrade to DRS version %d", drs.DrsVersion), | ||
}) | ||
if err != nil { | ||
return nil, fmt.Errorf("schedule upgrade: %w", err) | ||
} | ||
} | ||
|
||
return &types.MsgUpgradeDRSResponse{}, nil | ||
} | ||
|
||
// updateDrsVersion updates the DRS (Dynamic Rollup System) protocol version if it differs from the current version. | ||
// The function compares the new version against the existing one and updates the parameters if they differ. | ||
// | ||
// Returns: | ||
// - bool: true if the version was updated, false if no update was needed (versions were identical) | ||
func (m msgServer) updateDrsVersion(ctx sdk.Context, newVersion uint64) bool { | ||
currentParams := m.rollapParamsKeeper.GetParams(ctx) | ||
if currentParams.DrsVersion == uint32(newVersion) { | ||
return false | ||
} | ||
|
||
currentParams.DrsVersion = uint32(newVersion) | ||
m.rollapParamsKeeper.SetParams(ctx, currentParams) | ||
|
||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package types | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" | ||
"github.com/dymensionxyz/dymension-rdk/x/rollappparams/types" | ||
) | ||
|
||
type AccountKeeper interface { | ||
IterateAccounts(ctx sdk.Context, do func(i authtypes.AccountI) bool) | ||
SetAccount(ctx sdk.Context, acc authtypes.AccountI) | ||
} | ||
|
||
type RollappParamsKeeper interface { | ||
GetParams(ctx sdk.Context) (params types.Params) | ||
SetParams(ctx sdk.Context, params types.Params) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is weird, you're making a stack of errors
You should only call Join once