Skip to content

Commit

Permalink
Merge tag 'v0.47.13-evmos' into release/v0.47.x-evmos
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronc committed Feb 11, 2025
2 parents f008f84 + 8956c0f commit 7ac0f53
Show file tree
Hide file tree
Showing 10 changed files with 531 additions and 336 deletions.
584 changes: 301 additions & 283 deletions CHANGELOG.md

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -921,3 +921,8 @@ func (app *BaseApp) ProcessProposalVerifyTx(txBz []byte) (sdk.Tx, error) {
func (app *BaseApp) Close() error {
return nil
}

// ChainID returns the chainID of the BaseApp.
func (app *BaseApp) ChainID() string {
return app.chainID
}
13 changes: 7 additions & 6 deletions client/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/keyring"
)

// DefaultGasAdjustment is applied to gas estimates to avoid tx execution
// failures due to state changes that might occur between the tx simulation
// and the actual run.
var DefaultGasAdjustment = 1.0

const (
// DefaultGasAdjustment is applied to gas estimates to avoid tx execution
// failures due to state changes that might occur between the tx simulation
// and the actual run.
DefaultGasAdjustment = 1.0
DefaultGasLimit = 200000
GasFlagAuto = "auto"
DefaultGasLimit = 200000
GasFlagAuto = "auto"

// DefaultKeyringBackend
DefaultKeyringBackend = keyring.BackendOS
Expand Down
2 changes: 2 additions & 0 deletions proto/cosmos/staking/v1beta1/authz.proto
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@ enum AuthorizationType {
AUTHORIZATION_TYPE_UNDELEGATE = 2;
// AUTHORIZATION_TYPE_REDELEGATE defines an authorization type for Msg/BeginRedelegate
AUTHORIZATION_TYPE_REDELEGATE = 3;
// AUTHORIZATION_TYPE_CANCEL_UNBONDING_DELEGATION defines an authorization type for Msg/MsgCancelUnbondingDelegation
AUTHORIZATION_TYPE_CANCEL_UNBONDING_DELEGATION = 4;
}
32 changes: 32 additions & 0 deletions store/cachekv/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,38 @@ func (store *Store) CacheWrapWithTrace(w io.Writer, tc types.TraceContext) types
return NewStore(tracekv.NewStore(store, w, tc))
}

// Copy creates a deep copy of the Store object
func (store *Store) Copy() types.CacheKVStore {
store.mtx.Lock()
defer store.mtx.Unlock()

// Copy cache
cacheCopy := make(map[string]*cValue, len(store.cache))
for key, val := range store.cache {
newVal := *val // Create a copy of the cValue
cacheCopy[key] = &newVal
}

// Copy unsortedCache
unsortedCacheCopy := make(map[string]struct{}, len(store.unsortedCache))
for key := range store.unsortedCache {
unsortedCacheCopy[key] = struct{}{}
}

// Copy sortedCache
sortedCacheCopy := store.sortedCache.Copy()

// Create new Store with copied values
newStore := &Store{
cache: cacheCopy,
unsortedCache: unsortedCacheCopy,
sortedCache: sortedCacheCopy,
parent: store.parent,
}

return newStore
}

//----------------------------------------
// Iteration

Expand Down
26 changes: 26 additions & 0 deletions store/cachemulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,29 @@ func (cms Store) GetKVStore(key types.StoreKey) types.KVStore {
}
return store.(types.KVStore)
}

// Copy creates a deep copy of the Store object
func (cms Store) Copy() types.CacheMultiStore {
// Deep copy the db field
newDB := cms.db.Copy()

// Deep copy the cachekv stores map
newStores := make(map[types.StoreKey]types.CacheWrap, len(cms.stores))
for key, store := range cms.stores {
store, ok := store.(*cachekv.Store)
if ok {
newStores[key] = store.Copy()
}
}

// Create new Store with copied values
newStore := Store{
db: newDB,
stores: newStores,
keys: cms.keys,
traceWriter: cms.traceWriter,
traceContext: cms.traceContext,
}

return newStore
}
4 changes: 3 additions & 1 deletion store/types/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ type MultiStore interface {
// From MultiStore.CacheMultiStore()....
type CacheMultiStore interface {
MultiStore
Write() // Writes operations to underlying KVStore
Write() // Writes operations to underlying KVStore
Copy() CacheMultiStore // Returns a deep copy of the CacheMultiStore
}

// CommitMultiStore is an interface for a MultiStore without cache capabilities.
Expand Down Expand Up @@ -252,6 +253,7 @@ type CacheKVStore interface {

// Writes operations to underlying KVStore
Write()
Copy() CacheKVStore
}

// CommitKVStore is an interface for MultiStore.
Expand Down
52 changes: 43 additions & 9 deletions x/staking/types/authz.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,23 @@ func NewStakeAuthorization(allowed []sdk.ValAddress, denied []sdk.ValAddress, au

a := StakeAuthorization{}
if allowedValidators != nil {
a.Validators = &StakeAuthorization_AllowList{AllowList: &StakeAuthorization_Validators{Address: allowedValidators}}
a.Validators = &StakeAuthorization_AllowList{
AllowList: &StakeAuthorization_Validators{
Address: allowedValidators,
},
}
} else {
a.Validators = &StakeAuthorization_DenyList{DenyList: &StakeAuthorization_Validators{Address: deniedValidators}}
a.Validators = &StakeAuthorization_DenyList{
DenyList: &StakeAuthorization_Validators{
Address: deniedValidators,
},
}
}

if amount != nil {
a.MaxTokens = amount
}

a.AuthorizationType = authzType

return &a, nil
Expand All @@ -43,21 +52,30 @@ func (a StakeAuthorization) MsgTypeURL() string {
return authzType
}

// ValidateBasic performs a stateless validation of the fields.
// It fails if MaxTokens is either undefined or negative or if the authorization
// is unspecified.
func (a StakeAuthorization) ValidateBasic() error {
if a.MaxTokens != nil && a.MaxTokens.IsNegative() {
return sdkerrors.Wrapf(authz.ErrNegativeMaxTokens, "negative coin amount: %v", a.MaxTokens)
}

if a.AuthorizationType == AuthorizationType_AUTHORIZATION_TYPE_UNSPECIFIED {
return authz.ErrUnknownAuthorizationType
}

return nil
}

// Accept implements Authorization.Accept.
// Accept implements Authorization.Accept. It checks, that the validator is not in the denied list,
// and, should the allowed list not be empty, if the validator is in the allowed list.
// If these conditions are met, the authorization amount is validated and if successful, the
// corresponding AcceptResponse is returned.
func (a StakeAuthorization) Accept(ctx sdk.Context, msg sdk.Msg) (authz.AcceptResponse, error) {
var validatorAddress string
var amount sdk.Coin
var (
validatorAddress string
amount sdk.Coin
)

switch msg := msg.(type) {
case *MsgDelegate:
Expand All @@ -69,6 +87,9 @@ func (a StakeAuthorization) Accept(ctx sdk.Context, msg sdk.Msg) (authz.AcceptRe
case *MsgBeginRedelegate:
validatorAddress = msg.ValidatorDstAddress
amount = msg.Amount
case *MsgCancelUnbondingDelegation:
validatorAddress = msg.ValidatorAddress
amount = msg.Amount
default:
return authz.AcceptResponse{}, sdkerrors.ErrInvalidRequest.Wrap("unknown msg type")
}
Expand Down Expand Up @@ -97,21 +118,32 @@ func (a StakeAuthorization) Accept(ctx sdk.Context, msg sdk.Msg) (authz.AcceptRe

if a.MaxTokens == nil {
return authz.AcceptResponse{
Accept: true, Delete: false,
Updated: &StakeAuthorization{Validators: a.GetValidators(), AuthorizationType: a.GetAuthorizationType()},
Accept: true,
Delete: false,
Updated: &StakeAuthorization{
Validators: a.GetValidators(),
AuthorizationType: a.GetAuthorizationType(),
},
}, nil
}

limitLeft, err := a.MaxTokens.SafeSub(amount)
if err != nil {
return authz.AcceptResponse{}, err
}

if limitLeft.IsZero() {
return authz.AcceptResponse{Accept: true, Delete: true}, nil
}

return authz.AcceptResponse{
Accept: true, Delete: false,
Updated: &StakeAuthorization{Validators: a.GetValidators(), AuthorizationType: a.GetAuthorizationType(), MaxTokens: &limitLeft},
Accept: true,
Delete: false,
Updated: &StakeAuthorization{
Validators: a.GetValidators(),
AuthorizationType: a.GetAuthorizationType(),
MaxTokens: &limitLeft,
},
}, nil
}

Expand Down Expand Up @@ -149,6 +181,8 @@ func normalizeAuthzType(authzType AuthorizationType) (string, error) {
return sdk.MsgTypeURL(&MsgUndelegate{}), nil
case AuthorizationType_AUTHORIZATION_TYPE_REDELEGATE:
return sdk.MsgTypeURL(&MsgBeginRedelegate{}), nil
case AuthorizationType_AUTHORIZATION_TYPE_CANCEL_UNBONDING_DELEGATION:
return sdk.MsgTypeURL(&MsgCancelUnbondingDelegation{}), nil
default:
return "", sdkerrors.Wrapf(authz.ErrUnknownAuthorizationType, "cannot normalize authz type with %T", authzType)
}
Expand Down
78 changes: 41 additions & 37 deletions x/staking/types/authz.pb.go

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

Loading

0 comments on commit 7ac0f53

Please sign in to comment.