diff --git a/.github/workflows/sims.yml b/.github/workflows/sims.yml index 15ae3ffbc9..2c904ea224 100644 --- a/.github/workflows/sims.yml +++ b/.github/workflows/sims.yml @@ -1,15 +1,11 @@ name: Sims # Sims workflow runs multiple types of simulations (nondeterminism, import-export, after-import, multi-seed-short) # This workflow will run on all Pull Requests, if a .go, .mod or .sum file have been changed -env: - GOPRIVATE: "github.com/line/*" - -# TODO ebony: fix sim test failure on: -# pull_request: -# push: -# branches: -# - main + pull_request: + push: + branches: + - main jobs: cleanup-runs: @@ -62,6 +58,7 @@ jobs: with: PATTERNS: | **/**.go + !**/**_test.go go.mod go.sum - uses: actions/cache@v2.1.3 @@ -86,8 +83,9 @@ jobs: run: go version - uses: technote-space/get-diff-action@v5.0.1 with: - SUFFIX_FILTER: | + PATTERNS: | **/**.go + !**/**_test.go go.mod go.sum SET_ENV_NAME_INSERTIONS: 1 @@ -114,8 +112,9 @@ jobs: run: go version - uses: technote-space/get-diff-action@v5.0.1 with: - SUFFIX_FILTER: | + PATTERNS: | **/**.go + !**/**_test.go go.mod go.sum SET_ENV_NAME_INSERTIONS: 1 @@ -142,8 +141,9 @@ jobs: run: go version - uses: technote-space/get-diff-action@v5.0.1 with: - SUFFIX_FILTER: | + PATTERNS: | **/**.go + !**/**_test.go go.mod go.sum SET_ENV_NAME_INSERTIONS: 1 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c37ac4d5ae..69ef77d67b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -65,28 +65,28 @@ jobs: - name: Build run: GOOS=linux CGO_ENABLED=1 GOARCH=${{ matrix.goarch }} CC=${{ matrix.gcc }} LEDGER_ENABLED=false make build - # TODO: disable test-race. please enable this after fixing concurrent checkTx - # test-cosmovisor: - # runs-on: ubuntu-latest - # steps: - # - uses: actions/checkout@v2 - # - uses: actions/setup-go@v2.1.4 - # with: - # go-version: 1.15 - # - name: Display go version - # run: go version - # - uses: technote-space/get-diff-action@v5.0.1 - # id: git_diff - # with: - # PREFIX_FILTER: | - # cosmovisor - # PATTERNS: | - # **/**.go - # go.mod - # go.sum - # - name: Run cosmovisor tests - # run: cd cosmovisor; make - # if: env.GIT_DIFF +# TODO: disable test-cosmovisor; this test uses uploaded binary(cosmos-sdk) +# test-cosmovisor: +# runs-on: ubuntu-latest +# steps: +# - uses: actions/checkout@v2 +# - uses: actions/setup-go@v2.1.4 +# with: +# go-version: 1.15 +# - name: Display go version +# run: go version +# - uses: technote-space/get-diff-action@v5.0.1 +# id: git_diff +# with: +# PREFIX_FILTER: | +# cosmovisor +# PATTERNS: | +# **/**.go +# go.mod +# go.sum +# - name: Run cosmovisor tests +# run: cd cosmovisor; make +# if: env.GIT_DIFF split-test-files: runs-on: ubuntu-latest diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index c45d4f3bfe..f042ec6f0b 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -361,7 +361,7 @@ func (app *BaseApp) setCheckState(header ocproto.Header) { app.checkState = &state{ ms: ms, - ctx: ctx.WithConsensusParams(app.GetConsensusParams(ctx)), + ctx: ctx, } } diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index aea9ed50ce..2cc4f029a2 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -2070,7 +2070,7 @@ source tracing information path. ### FungibleTokenPacketData FungibleTokenPacketData defines a struct for the packet payload See FungibleTokenPacketData spec: -https://github.com/cosmos/ics/tree/master/spec/ics-020-fungible-token-transfer#data-structures +https://github.com/cosmos/ibc/tree/master/spec/app/ics-020-fungible-token-transfer#data-structures | Field | Type | Label | Description | @@ -2401,7 +2401,7 @@ Params defines the set of IBC light client parameters. ### MsgTransfer MsgTransfer defines a msg to transfer fungible tokens (i.e Coins) between ICS20 enabled chains. See ICS Spec here: -https://github.com/cosmos/ics/tree/master/spec/ics-020-fungible-token-transfer#data-structures +https://github.com/cosmos/ics/tree/master/spec/app/ics-020-fungible-token-transfer#data-structures | Field | Type | Label | Description | @@ -2464,7 +2464,7 @@ NOTE: The field numbers 21 and 22 were explicitly chosen to avoid accidental conflicts with other protobuf message formats used for acknowledgements. The first byte of any message with this format will be the non-ASCII values `0xaa` (result) or `0xb2` (error). Implemented as defined by ICS: -https://github.com/cosmos/ics/tree/master/spec/ics-004-channel-and-packet-semantics#acknowledgement-envelope +https://github.com/cosmos/ibc/tree/master/spec/core/ics-004-channel-and-packet-semantics#acknowledgement-envelope | Field | Type | Label | Description | diff --git a/x/auth/simulation/genesis.go b/x/auth/simulation/genesis.go index 48d36366da..a742d40dfe 100644 --- a/x/auth/simulation/genesis.go +++ b/x/auth/simulation/genesis.go @@ -89,7 +89,8 @@ func GenSigVerifyCostSECP256K1(r *rand.Rand) uint64 { } func GenValidSigBlockPeriod(r *rand.Rand) uint64 { - return uint64(simulation.RandIntBetween(r, 1, 1000)) + // We use valid sig block period greater than 100 for testing + return uint64(simulation.RandIntBetween(r, 100, 1000)) } // RandomizedGenState generates a random GenesisState for auth diff --git a/x/auth/types/account.go b/x/auth/types/account.go index ed529cf4e3..bf071aceda 100644 --- a/x/auth/types/account.go +++ b/x/auth/types/account.go @@ -31,6 +31,10 @@ var ( BaseAccountSig = []byte("bacc") ModuleAccountSig = []byte("macc") + + PubKeyTypeSecp256k1 = byte(1) + PubKeyTypeEd25519 = byte(2) + PubKeyTypeMultisig = byte(3) ) // NewBaseAccount creates a new BaseAccount object @@ -407,10 +411,14 @@ type GenesisAccount interface { // custom json marshaler for BaseAccount & ModuleAccount +type PubKeyJSON struct { + Type byte `json:"type"` + Key []byte `json:"key"` +} type BaseAccountJSON struct { - Address string `json:"address"` - PubKey json.RawMessage `json:"pub_key"` - Sequence string `json:"sequence"` + Address string `json:"address"` + PubKey PubKeyJSON `json:"pub_key"` + Sequence string `json:"sequence"` } func (acc BaseAccount) MarshalJSONPB(m *jsonpb.Marshaler) ([]byte, error) { @@ -420,19 +428,22 @@ func (acc BaseAccount) MarshalJSONPB(m *jsonpb.Marshaler) ([]byte, error) { bi.Sequence = strconv.FormatUint(acc.Sequence, 10) var bz []byte var err error - if acc.Ed25519PubKey != nil { - bz, err = codec.ProtoMarshalJSON(acc.Ed25519PubKey, m.AnyResolver) - } if acc.Secp256K1PubKey != nil { - bz, err = codec.ProtoMarshalJSON(acc.Secp256K1PubKey, m.AnyResolver) + bi.PubKey.Type = PubKeyTypeSecp256k1 + bz, err = acc.Secp256K1PubKey.Marshal() + } + if acc.Ed25519PubKey != nil { + bi.PubKey.Type = PubKeyTypeEd25519 + bz, err = acc.Ed25519PubKey.Marshal() } if acc.MultisigPubKey != nil { - bz, err = codec.ProtoMarshalJSON(acc.MultisigPubKey, m.AnyResolver) + bi.PubKey.Type = PubKeyTypeMultisig + bz, err = acc.MultisigPubKey.Marshal() } if err != nil { return nil, err } - bi.PubKey = bz + bi.PubKey.Key = bz return json.Marshal(bi) } @@ -443,12 +454,6 @@ func (acc *BaseAccount) UnmarshalJSONPB(m *jsonpb.Unmarshaler, bz []byte) error if err != nil { return err } - /* TODO: do we need to validate address format here - err = sdk.ValidateAccAddress(bi.Address) - if err != nil { - return err - } - */ acc.Address = bi.Address acc.Sequence, err = strconv.ParseUint(bi.Sequence, 10, 64) @@ -456,29 +461,25 @@ func (acc *BaseAccount) UnmarshalJSONPB(m *jsonpb.Unmarshaler, bz []byte) error return err } - done := false - if !done { + switch bi.PubKey.Type { + case PubKeyTypeSecp256k1: pk := new(secp256k1.PubKey) - any, _ := codectypes.NewAnyWithValue(pk) - if m.Unmarshal(strings.NewReader(string(bi.PubKey)), any) == nil { - acc.SetPubKey(pk) - done = true + if err := pk.Unmarshal(bi.PubKey.Key); err != nil { + return err } - } - if !done { - pk := new(ed25519.PubKey) - any, _ := codectypes.NewAnyWithValue(pk) - if m.Unmarshal(strings.NewReader(string(bi.PubKey)), any) == nil { - acc.SetPubKey(pk) - done = true + acc.SetPubKey(pk) + case PubKeyTypeEd25519: + pk := new(secp256k1.PubKey) + if err := pk.Unmarshal(bi.PubKey.Key); err != nil { + return err } - } - if !done { + acc.SetPubKey(pk) + case PubKeyTypeMultisig: pk := new(multisig.LegacyAminoPubKey) - any, _ := codectypes.NewAnyWithValue(pk) - if m.Unmarshal(strings.NewReader(string(bi.PubKey)), any) == nil { - acc.SetPubKey(pk) + if err := pk.Unmarshal(bi.PubKey.Key); err != nil { + return err } + acc.SetPubKey(pk) } return nil } diff --git a/x/auth/types/account_test.go b/x/auth/types/account_test.go index 8cc5dd7db5..0a2ecd76cd 100644 --- a/x/auth/types/account_test.go +++ b/x/auth/types/account_test.go @@ -6,6 +6,8 @@ import ( "fmt" "testing" + "github.com/line/lbm-sdk/codec" + types2 "github.com/line/lbm-sdk/codec/types" "github.com/stretchr/testify/require" yaml "gopkg.in/yaml.v2" @@ -48,6 +50,21 @@ func TestBaseAddressPubKey(t *testing.T) { require.EqualValues(t, addr2, acc2.GetAddress()) } +func TestBaseAccountMarshalUnmarshalJSON(t *testing.T) { + interfaceRegistry := types2.NewInterfaceRegistry() + + cdc := codec.NewProtoCodec(interfaceRegistry) + _, pub, addr := testdata.KeyTestPubAddr() + acc := types.NewBaseAccountWithAddress(addr) + acc.SetPubKey(pub) + + bz := cdc.MustMarshalJSON(acc) + var acc2 types.BaseAccount + + cdc.MustUnmarshalJSON(bz, &acc2) + require.Equal(t, acc, &acc2) +} + func TestBaseSequence(t *testing.T) { _, _, addr := testdata.KeyTestPubAddr() acc := types.NewBaseAccountWithAddress(addr) diff --git a/x/auth/vesting/types/vesting_account.go b/x/auth/vesting/types/vesting_account.go index b4b1f66853..4331c5460b 100644 --- a/x/auth/vesting/types/vesting_account.go +++ b/x/auth/vesting/types/vesting_account.go @@ -1,9 +1,11 @@ package types import ( + "encoding/json" "errors" "time" + "github.com/gogo/protobuf/jsonpb" yaml "gopkg.in/yaml.v2" sdk "github.com/line/lbm-sdk/types" @@ -209,6 +211,54 @@ func (bva BaseVestingAccount) MarshalYAML() (interface{}, error) { return string(bz), err } +type vestingAccountJSON struct { + BaseAccount json.RawMessage `json:"base_account"` + OriginalVesting sdk.Coins `json:"original_vesting"` + DelegatedFree sdk.Coins `json:"delegated_free"` + DelegatedVesting sdk.Coins `json:"delegated_vesting"` + EndTime int64 `json:"end_time"` + + StartTime int64 `json:"start_time,omitempty"` + VestingPeriods Periods `json:"vesting_periods,omitempty"` +} + +func (bva BaseVestingAccount) MarshalJSONPB(m *jsonpb.Marshaler) ([]byte, error) { + bz, err := bva.BaseAccount.MarshalJSONPB(m) + if err != nil { + return nil, err + } + alias := vestingAccountJSON{ + BaseAccount: bz, + OriginalVesting: bva.OriginalVesting, + DelegatedFree: bva.DelegatedFree, + DelegatedVesting: bva.DelegatedVesting, + EndTime: bva.EndTime, + } + + return json.Marshal(alias) +} + +func (bva *BaseVestingAccount) UnmarshalJSONPB(m *jsonpb.Unmarshaler, bz []byte) error { + var va vestingAccountJSON + + err := json.Unmarshal(bz, &va) + if err != nil { + return err + } + + var ba authtypes.BaseAccount + if err := (&ba).UnmarshalJSONPB(m, va.BaseAccount); err != nil { + return err + } + bva.BaseAccount = &ba + bva.OriginalVesting = va.OriginalVesting + bva.DelegatedFree = va.DelegatedFree + bva.OriginalVesting = va.DelegatedVesting + bva.EndTime = va.EndTime + + return nil +} + //----------------------------------------------------------------------------- // Continuous Vesting Account @@ -332,6 +382,45 @@ func (cva ContinuousVestingAccount) MarshalYAML() (interface{}, error) { return string(bz), err } +func (cva ContinuousVestingAccount) MarshalJSONPB(m *jsonpb.Marshaler) ([]byte, error) { + bz, err := cva.BaseVestingAccount.BaseAccount.MarshalJSONPB(m) + if err != nil { + return nil, err + } + alias := vestingAccountJSON{ + BaseAccount: bz, + OriginalVesting: cva.BaseVestingAccount.OriginalVesting, + DelegatedFree: cva.BaseVestingAccount.DelegatedFree, + DelegatedVesting: cva.BaseVestingAccount.DelegatedVesting, + EndTime: cva.BaseVestingAccount.EndTime, + StartTime: cva.StartTime, + } + return json.Marshal(alias) +} + +func (cva *ContinuousVestingAccount) UnmarshalJSONPB(m *jsonpb.Unmarshaler, bz []byte) error { + var va vestingAccountJSON + + err := json.Unmarshal(bz, &va) + if err != nil { + return err + } + + var ba authtypes.BaseAccount + if err := (&ba).UnmarshalJSONPB(m, va.BaseAccount); err != nil { + return err + } + cva.BaseVestingAccount = &BaseVestingAccount{ + BaseAccount: &ba, + OriginalVesting: va.OriginalVesting, + DelegatedFree: va.DelegatedFree, + DelegatedVesting: va.DelegatedVesting, + EndTime: va.EndTime, + } + cva.StartTime = va.StartTime + return nil +} + //----------------------------------------------------------------------------- // Periodic Vesting Account @@ -485,6 +574,49 @@ func (pva PeriodicVestingAccount) MarshalYAML() (interface{}, error) { return string(bz), err } +func (pva PeriodicVestingAccount) MarshalJSONPB(m *jsonpb.Marshaler) ([]byte, error) { + bz, err := pva.BaseVestingAccount.BaseAccount.MarshalJSONPB(m) + if err != nil { + return nil, err + } + alias := vestingAccountJSON{ + BaseAccount: bz, + OriginalVesting: pva.BaseVestingAccount.OriginalVesting, + DelegatedFree: pva.BaseVestingAccount.DelegatedFree, + DelegatedVesting: pva.BaseVestingAccount.DelegatedVesting, + EndTime: pva.BaseVestingAccount.EndTime, + StartTime: pva.StartTime, + VestingPeriods: pva.VestingPeriods, + } + + return json.Marshal(alias) +} + +func (pva *PeriodicVestingAccount) UnmarshalJSONPB(m *jsonpb.Unmarshaler, bz []byte) error { + var va vestingAccountJSON + + err := json.Unmarshal(bz, &va) + if err != nil { + return err + } + + var ba authtypes.BaseAccount + if err := (&ba).UnmarshalJSONPB(m, va.BaseAccount); err != nil { + return err + } + pva.BaseVestingAccount = &BaseVestingAccount{ + BaseAccount: &ba, + OriginalVesting: va.OriginalVesting, + DelegatedFree: va.DelegatedFree, + DelegatedVesting: va.DelegatedVesting, + EndTime: va.EndTime, + } + pva.StartTime = va.StartTime + pva.VestingPeriods = va.VestingPeriods + + return nil +} + //----------------------------------------------------------------------------- // Delayed Vesting Account @@ -551,3 +683,42 @@ func (dva DelayedVestingAccount) String() string { out, _ := dva.MarshalYAML() return out.(string) } + +func (dva DelayedVestingAccount) MarshalJSONPB(m *jsonpb.Marshaler) ([]byte, error) { + bz, err := dva.BaseAccount.MarshalJSONPB(m) + if err != nil { + return nil, err + } + alias := vestingAccountJSON{ + BaseAccount: bz, + OriginalVesting: dva.BaseVestingAccount.OriginalVesting, + DelegatedFree: dva.BaseVestingAccount.DelegatedFree, + DelegatedVesting: dva.BaseVestingAccount.DelegatedVesting, + EndTime: dva.BaseVestingAccount.EndTime, + } + + return json.Marshal(alias) +} + +func (dva *DelayedVestingAccount) UnmarshalJSONPB(m *jsonpb.Unmarshaler, bz []byte) error { + var va vestingAccountJSON + + err := json.Unmarshal(bz, &va) + if err != nil { + return err + } + + var ba authtypes.BaseAccount + if err := (&ba).UnmarshalJSONPB(m, va.BaseAccount); err != nil { + return err + } + dva.BaseVestingAccount = &BaseVestingAccount{ + BaseAccount: &ba, + OriginalVesting: va.OriginalVesting, + DelegatedFree: va.DelegatedFree, + DelegatedVesting: va.DelegatedVesting, + EndTime: va.EndTime, + } + + return nil +} diff --git a/x/distribution/keeper/hooks.go b/x/distribution/keeper/hooks.go index 753f397d96..aa0702ea3d 100644 --- a/x/distribution/keeper/hooks.go +++ b/x/distribution/keeper/hooks.go @@ -43,7 +43,7 @@ func (h Hooks) AfterValidatorRemoved(ctx sdk.Context, _ sdk.ConsAddress, valAddr // add to validator account if !coins.IsZero() { - accAddr := sdk.AccAddress(valAddr) + accAddr := valAddr.ToAccAddress() withdrawAddr := h.k.GetDelegatorWithdrawAddr(ctx, accAddr) if err := h.k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, withdrawAddr, coins); err != nil { diff --git a/x/distribution/types/keys.go b/x/distribution/types/keys.go index db38a7150f..714521e694 100644 --- a/x/distribution/types/keys.go +++ b/x/distribution/types/keys.go @@ -100,9 +100,9 @@ func GetValidatorAccumulatedCommissionAddress(key []byte) (valAddr sdk.ValAddres // gets the height from a validator's slash event key func GetValidatorSlashEventAddressHeight(key []byte) (valAddr sdk.ValAddress, height uint64) { - addr := key[1 : len(key)-8] + addr := key[1 : len(key)-16] // 8 bytes height + 8 bytes period valAddr = sdk.ValAddress(addr) - b := key[len(key)-8:] // the next 8 bytes represent the height + b := key[len(key)-16 : len(key)-8] // the next 8 bytes represent the height height = binary.BigEndian.Uint64(b) return } diff --git a/x/params/types/subspace.go b/x/params/types/subspace.go index a37518fd66..0cea9f8823 100644 --- a/x/params/types/subspace.go +++ b/x/params/types/subspace.go @@ -3,8 +3,6 @@ package types import ( "fmt" "reflect" - "sync/atomic" - "unsafe" "github.com/line/lbm-sdk/codec" "github.com/line/lbm-sdk/store/prefix" @@ -91,27 +89,18 @@ func (s *Subspace) Validate(ctx sdk.Context, key []byte, value interface{}) erro func (s *Subspace) Get(ctx sdk.Context, key []byte, ptr interface{}) { s.checkType(key, ptr) - if s.loadFromCache(key, ptr) { - // cache hit - return - } store := s.kvStore(ctx) bz := store.Get(key) if err := s.legacyAmino.UnmarshalJSON(bz, ptr); err != nil { panic(err) } - s.cacheValue(key, ptr) } // GetIfExists queries for a parameter by key from the Subspace's KVStore and // sets the value to the provided pointer. If the value does not exist, it will // perform a no-op. func (s *Subspace) GetIfExists(ctx sdk.Context, key []byte, ptr interface{}) { - if s.loadFromCache(key, ptr) { - // cache hit - return - } store := s.kvStore(ctx) bz := store.Get(key) if bz == nil { @@ -123,7 +112,6 @@ func (s *Subspace) GetIfExists(ctx sdk.Context, key []byte, ptr interface{}) { if err := s.legacyAmino.UnmarshalJSON(bz, ptr); err != nil { panic(err) } - s.cacheValue(key, ptr) } // GetRaw queries for the raw values bytes for a parameter by key. @@ -134,9 +122,6 @@ func (s *Subspace) GetRaw(ctx sdk.Context, key []byte) []byte { // Has returns if a parameter key exists or not in the Subspace's KVStore. func (s *Subspace) Has(ctx sdk.Context, key []byte) bool { - if s.hasCache(key) { - return true - } store := s.kvStore(ctx) return store.Has(key) } @@ -159,69 +144,6 @@ func (s *Subspace) checkType(key []byte, value interface{}) { } } -// All the cache-related functions here are thread-safe. -// Currently, since `CheckTx` and `DeliverTx` can run without abci locking, -// these functions must be thread-safe as tx can run concurrently. -// The map data type is not thread-safe by itself, but concurrent access is -// possible with entry fixed. If we access the subspace with an unregistered key, -// it panics, ensuring that the entry of the map is not extended after the server runs. -// Value update and read operations for a single entry of a map can be performed concurrently by -// `atomic.StorePointer` and `atomic.LoadPointer`. -func (s *Subspace) cacheValue(key []byte, value interface{}) { - attr, ok := s.table.m[string(key)] - if !ok { - panic(fmt.Sprintf("parameter %s not registered", string(key))) - } - val := reflect.ValueOf(value) - if reflect.TypeOf(value).Kind() == reflect.Ptr { - val = val.Elem() - } - valueToBeCached := reflect.New(val.Type()) - valueToBeCached.Elem().Set(val) - atomic.StorePointer(&attr.cachedValue, unsafe.Pointer(&valueToBeCached)) -} - -func (s *Subspace) hasCache(key []byte) bool { - attr, ok := s.table.m[string(key)] - if !ok { - panic(fmt.Sprintf("parameter %s not registered", string(key))) - } - cachedValuePtr := (*reflect.Value)(atomic.LoadPointer(&attr.cachedValue)) - return cachedValuePtr != nil -} - -func (s *Subspace) loadFromCache(key []byte, value interface{}) bool { - attr, ok := s.table.m[string(key)] - if !ok { - return false - } - if reflect.TypeOf(value).Kind() != reflect.Ptr { - panic("value should be a Pointer") - } - - cachedValuePtr := (*reflect.Value)(atomic.LoadPointer(&attr.cachedValue)) - if cachedValuePtr == nil { - return false - } - reflect.ValueOf(value).Elem().Set((*cachedValuePtr).Elem()) - return true -} - -// Only for test -func (s *Subspace) GetCachedValueForTesting(key []byte, value interface{}) bool { - return s.loadFromCache(key, value) -} - -// Only for test -func (s *Subspace) HasCacheForTesting(key []byte) bool { - return s.hasCache(key) -} - -// Only for test -func (s *Subspace) SetCacheForTesting(key []byte, value interface{}) { - s.cacheValue(key, value) -} - // Set stores a value for given a parameter key assuming the parameter type has // been registered. It will panic if the parameter type has not been registered // or if the value cannot be encoded. A change record is also set in the Subspace's @@ -236,7 +158,6 @@ func (s *Subspace) Set(ctx sdk.Context, key []byte, value interface{}) { } store.Set(key, bz) - s.cacheValue(key, value) } // Update stores an updated raw value for a given parameter key assuming the diff --git a/x/params/types/subspace_test.go b/x/params/types/subspace_test.go index 43519d9941..15fc26f1dc 100644 --- a/x/params/types/subspace_test.go +++ b/x/params/types/subspace_test.go @@ -187,55 +187,6 @@ func (suite *SubspaceTestSuite) TestSetParamSet() { suite.Require().Equal(a.BondDenom, b.BondDenom) } -func (suite *SubspaceTestSuite) TestParamSetCache() { - a := params{ - UnbondingTime: time.Hour * 48, - MaxValidators: 100, - BondDenom: "stake", - } - b := params{} - // confirm cache is empty - suite.Require().False(suite.ss.GetCachedValueForTesting(keyUnbondingTime, &b.UnbondingTime)) - suite.Require().False(suite.ss.GetCachedValueForTesting(keyMaxValidators, &b.MaxValidators)) - suite.Require().False(suite.ss.GetCachedValueForTesting(keyBondDenom, &b.BondDenom)) - suite.Require().False(suite.ss.HasCacheForTesting(keyUnbondingTime)) - suite.Require().False(suite.ss.HasCacheForTesting(keyMaxValidators)) - suite.Require().False(suite.ss.HasCacheForTesting(keyBondDenom)) - suite.Require().NotEqual(a, b) - - suite.Require().NotPanics(func() { - suite.ss.SetParamSet(suite.ctx, &a) - }) - // confirm cached - suite.Require().True(suite.ss.GetCachedValueForTesting(keyUnbondingTime, &b.UnbondingTime)) - suite.Require().True(suite.ss.GetCachedValueForTesting(keyMaxValidators, &b.MaxValidators)) - suite.Require().True(suite.ss.GetCachedValueForTesting(keyBondDenom, &b.BondDenom)) - suite.Require().Equal(a, b) - - // update local variable - a.UnbondingTime = time.Hour * 24 - a.MaxValidators = 50 - a.BondDenom = "link" - - // confirm the cache is not updated - c := params{} - suite.Require().True(suite.ss.GetCachedValueForTesting(keyUnbondingTime, &c.UnbondingTime)) - suite.Require().True(suite.ss.GetCachedValueForTesting(keyMaxValidators, &c.MaxValidators)) - suite.Require().True(suite.ss.GetCachedValueForTesting(keyBondDenom, &c.BondDenom)) - suite.Require().Equal(b, c) // cached value is not updated - - // update only cache - suite.ss.SetCacheForTesting(keyUnbondingTime, &a.UnbondingTime) - suite.ss.SetCacheForTesting(keyMaxValidators, &a.MaxValidators) - suite.ss.SetCacheForTesting(keyBondDenom, &a.BondDenom) - - // ensure GetParamSet to get value not from db but from cache - suite.Require().NotPanics(func() { - suite.ss.GetParamSet(suite.ctx, &c) - }) - suite.Require().Equal(a, c) -} - func (suite *SubspaceTestSuite) TestName() { suite.Require().Equal("testsubspace", suite.ss.Name()) } diff --git a/x/params/types/table.go b/x/params/types/table.go index 89416eab4c..226117d1bc 100644 --- a/x/params/types/table.go +++ b/x/params/types/table.go @@ -2,15 +2,13 @@ package types import ( "reflect" - "unsafe" sdk "github.com/line/lbm-sdk/types" ) type attribute struct { - ty reflect.Type - vfn ValueValidatorFn - cachedValue unsafe.Pointer + ty reflect.Type + vfn ValueValidatorFn } // KeyTable subspaces appropriate type for each parameter key diff --git a/x/slashing/keeper/hooks.go b/x/slashing/keeper/hooks.go index d67a01211d..19020ae56b 100644 --- a/x/slashing/keeper/hooks.go +++ b/x/slashing/keeper/hooks.go @@ -3,8 +3,6 @@ package keeper import ( "time" - "github.com/line/ostracon/crypto" - sdk "github.com/line/lbm-sdk/types" "github.com/line/lbm-sdk/x/slashing/types" ) @@ -39,7 +37,8 @@ func (k Keeper) AfterValidatorCreated(ctx sdk.Context, valAddr sdk.ValAddress) e // AfterValidatorRemoved deletes the address-pubkey relation when a validator is removed, func (k Keeper) AfterValidatorRemoved(ctx sdk.Context, address sdk.ConsAddress) { - k.deleteAddrPubkeyRelation(ctx, crypto.Address(address)) + addrBytes, _ := sdk.ConsAddressToBytes(address.String()) + k.deleteAddrPubkeyRelation(ctx, addrBytes) } //_________________________________________________________________________________________