Skip to content

Commit

Permalink
Merge pull request #9 from torao/fix/issue578
Browse files Browse the repository at this point in the history
  • Loading branch information
ulbqb authored Jul 19, 2022
2 parents a90b481 + a47acef commit c431caf
Show file tree
Hide file tree
Showing 72 changed files with 179 additions and 529 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (proto) [\#584](https://github.com/line/lbm-sdk/pull/564) remove `prove` field in the `GetTxsEventRequest` of `tx` proto
* (x/collection) [\#571](https://github.com/line/lbm-sdk/pull/571) add x/collection proto
* (x/collection) [\#574](https://github.com/line/lbm-sdk/pull/574) implement x/collection
* (amino) [\600](https://github.com/line/lbm-sdk/pull/600) change amino codec path from `lbm-sdk/` to `cosmos-sdk/`

### Improvements

Expand Down
6 changes: 0 additions & 6 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (
"github.com/line/lbm-sdk/telemetry"
sdk "github.com/line/lbm-sdk/types"
sdkerrors "github.com/line/lbm-sdk/types/errors"

iavlstore "github.com/line/lbm-sdk/store/iavl"
)

// InitChain implements the ABCI interface. It runs the initialization logic
Expand Down Expand Up @@ -280,13 +278,11 @@ func (app *BaseApp) CheckTxAsync(req abci.RequestCheckTx, callback abci.CheckTxC
func (app *BaseApp) BeginRecheckTx(req abci.RequestBeginRecheckTx) abci.ResponseBeginRecheckTx {
// NOTE: This is safe because Ostracon holds a lock on the mempool for Rechecking.
app.setCheckState(req.Header)
iavlstore.PausePrefetcher()
return abci.ResponseBeginRecheckTx{Code: abci.CodeTypeOK}
}

// EndRecheckTx implements the ABCI interface.
func (app *BaseApp) EndRecheckTx(req abci.RequestEndRecheckTx) abci.ResponseEndRecheckTx {
iavlstore.ResumePrefetcher()
return abci.ResponseEndRecheckTx{Code: abci.CodeTypeOK}
}

Expand Down Expand Up @@ -344,9 +340,7 @@ func (app *BaseApp) Commit() (res abci.ResponseCommit) {
// The write to the DeliverTx state writes all state transitions to the root
// MultiStore (app.cms) so when Commit() is called is persists those values.
app.deliverState.ms.Write()
iavlstore.PausePrefetcher()
commitID := app.cms.Commit()
iavlstore.ResumePrefetcher()
app.logger.Info("commit synced", "commit", fmt.Sprintf("%X", commitID))

// iavl, db & disk stats
Expand Down
12 changes: 6 additions & 6 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ func registerTestCodec(cdc *codec.LegacyAmino) {
sdk.RegisterLegacyAminoCodec(cdc)

// register test types
cdc.RegisterConcrete(&txTest{}, "lbm-sdk/baseapp/txTest", nil)
cdc.RegisterConcrete(&msgCounter{}, "lbm-sdk/baseapp/msgCounter", nil)
cdc.RegisterConcrete(&msgCounter2{}, "lbm-sdk/baseapp/msgCounter2", nil)
cdc.RegisterConcrete(&msgKeyValue{}, "lbm-sdk/baseapp/msgKeyValue", nil)
cdc.RegisterConcrete(&msgNoRoute{}, "lbm-sdk/baseapp/msgNoRoute", nil)
cdc.RegisterConcrete(&txTest{}, "cosmos-sdk/baseapp/txTest", nil)
cdc.RegisterConcrete(&msgCounter{}, "cosmos-sdk/baseapp/msgCounter", nil)
cdc.RegisterConcrete(&msgCounter2{}, "cosmos-sdk/baseapp/msgCounter2", nil)
cdc.RegisterConcrete(&msgKeyValue{}, "cosmos-sdk/baseapp/msgKeyValue", nil)
cdc.RegisterConcrete(&msgNoRoute{}, "cosmos-sdk/baseapp/msgNoRoute", nil)
}

// aminoTxEncoder creates a amino TxEncoder for testing purposes.
Expand Down Expand Up @@ -1259,7 +1259,7 @@ func TestRunInvalidTransaction(t *testing.T) {
// new codec so we can encode the tx, but we shouldn't be able to decode
newCdc := codec.NewLegacyAmino()
registerTestCodec(newCdc)
newCdc.RegisterConcrete(&msgNoDecode{}, "lbm-sdk/baseapp/msgNoDecode", nil)
newCdc.RegisterConcrete(&msgNoDecode{}, "cosmos-sdk/baseapp/msgNoDecode", nil)

txBytes, err := newCdc.Marshal(tx)
require.NoError(t, err)
Expand Down
11 changes: 0 additions & 11 deletions baseapp/grpcrouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package baseapp

import (
"fmt"
"sync"

gogogrpc "github.com/gogo/protobuf/grpc"
"google.golang.org/grpc"
Expand All @@ -20,7 +19,6 @@ var protoCodec = encoding.GetCodec(proto.Name)

// GRPCQueryRouter routes ABCI Query requests to GRPC handlers
type GRPCQueryRouter struct {
lck sync.Mutex
routes map[string]GRPCQueryHandler
interfaceRegistry codectypes.InterfaceRegistry
serviceData []serviceData
Expand All @@ -37,7 +35,6 @@ var _ gogogrpc.Server = &GRPCQueryRouter{}
// NewGRPCQueryRouter creates a new GRPCQueryRouter
func NewGRPCQueryRouter() *GRPCQueryRouter {
return &GRPCQueryRouter{
lck: sync.Mutex{},
routes: map[string]GRPCQueryHandler{},
}
}
Expand All @@ -49,8 +46,6 @@ type GRPCQueryHandler = func(ctx sdk.Context, req abci.RequestQuery) (abci.Respo
// Route returns the GRPCQueryHandler for a given query route path or nil
// if not found
func (qrt *GRPCQueryRouter) Route(path string) GRPCQueryHandler {
qrt.lck.Lock()
defer qrt.lck.Unlock()
handler, found := qrt.routes[path]
if !found {
return nil
Expand All @@ -64,9 +59,6 @@ func (qrt *GRPCQueryRouter) Route(path string) GRPCQueryHandler {
// This functions PANICS:
// - if a protobuf service is registered twice.
func (qrt *GRPCQueryRouter) RegisterService(sd *grpc.ServiceDesc, handler interface{}) {
qrt.lck.Lock()
defer qrt.lck.Unlock()

// adds a top-level query handler based on the gRPC service name
for _, method := range sd.Methods {
fqName := fmt.Sprintf("/%s/%s", sd.ServiceName, method.MethodName)
Expand Down Expand Up @@ -127,9 +119,6 @@ func (qrt *GRPCQueryRouter) RegisterService(sd *grpc.ServiceDesc, handler interf
// SetInterfaceRegistry sets the interface registry for the router. This will
// also register the interface reflection gRPC service.
func (qrt *GRPCQueryRouter) SetInterfaceRegistry(interfaceRegistry codectypes.InterfaceRegistry) {
// qrt.lck.Lock()
// defer qrt.lck.Unlock()

qrt.interfaceRegistry = interfaceRegistry
// Once we have an interface registry, we can register the interface
// registry reflection gRPC service.
Expand Down
2 changes: 1 addition & 1 deletion codec/amino_codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func TestAminoCodecUnpackAnyFails(t *testing.T) {

func TestAminoCodecFullDecodeAndEncode(t *testing.T) {
// This tx comes from https://github.com/cosmos/cosmos-sdk/issues/8117.
txSigned := `{"type":"lbm-sdk/StdTx","value":{"msg":[{"type":"lbm-sdk/MsgCreateValidator","value":{"description":{"moniker":"fulltest","identity":"satoshi","website":"example.com","details":"example inc"},"commission":{"rate":"0.500000000000000000","max_rate":"1.000000000000000000","max_change_rate":"0.200000000000000000"},"min_self_delegation":"1000000","delegator_address":"link14pt0q5cwf38zt08uu0n6yrstf3rndzr5057jys","validator_address":"linkvaloper14pt0q5cwf38zt08uu0n6yrstf3rndzr52q28gr","pubkey":{"type":"ostracon/PubKeyEd25519","value":"CYrOiM3HtS7uv1B1OAkknZnFYSRpQYSYII8AtMMtev0="},"value":{"denom":"umuon","amount":"700000000"}}}],"fee":{"amount":[{"denom":"umuon","amount":"6000"}],"gas":"160000"},"signatures":[{"pub_key":{"type":"ostracon/PubKeySecp256k1","value":"AwAOXeWgNf1FjMaayrSnrOOKz+Fivr6DiI/i0x0sZCHw"},"signature":"RcnfS/u2yl7uIShTrSUlDWvsXo2p2dYu6WJC8VDVHMBLEQZWc8bsINSCjOnlsIVkUNNe1q/WCA9n3Gy1+0zhYA=="}],"memo":"","timeout_height":"0"}}`
txSigned := `{"type":"cosmos-sdk/StdTx","value":{"msg":[{"type":"cosmos-sdk/MsgCreateValidator","value":{"description":{"moniker":"fulltest","identity":"satoshi","website":"example.com","details":"example inc"},"commission":{"rate":"0.500000000000000000","max_rate":"1.000000000000000000","max_change_rate":"0.200000000000000000"},"min_self_delegation":"1000000","delegator_address":"link14pt0q5cwf38zt08uu0n6yrstf3rndzr5057jys","validator_address":"linkvaloper14pt0q5cwf38zt08uu0n6yrstf3rndzr52q28gr","pubkey":{"type":"ostracon/PubKeyEd25519","value":"CYrOiM3HtS7uv1B1OAkknZnFYSRpQYSYII8AtMMtev0="},"value":{"denom":"umuon","amount":"700000000"}}}],"fee":{"amount":[{"denom":"umuon","amount":"6000"}],"gas":"160000"},"signatures":[{"pub_key":{"type":"ostracon/PubKeySecp256k1","value":"AwAOXeWgNf1FjMaayrSnrOOKz+Fivr6DiI/i0x0sZCHw"},"signature":"RcnfS/u2yl7uIShTrSUlDWvsXo2p2dYu6WJC8VDVHMBLEQZWc8bsINSCjOnlsIVkUNNe1q/WCA9n3Gy1+0zhYA=="}],"memo":"","timeout_height":"0"}}`
var legacyCdc = simapp.MakeTestEncodingConfig().Amino
var tx legacytx.StdTx
err := legacyCdc.UnmarshalJSON([]byte(txSigned), &tx)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ require (
github.com/rogpeppe/go-internal v1.8.1 // indirect
github.com/rs/zerolog v1.27.0
github.com/spf13/cast v1.5.0
github.com/spf13/cobra v1.4.0
github.com/spf13/cobra v1.5.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.12.0
github.com/stretchr/testify v1.8.0
Expand Down
4 changes: 3 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwc
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4=
Expand Down Expand Up @@ -1013,8 +1014,9 @@ github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3
github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE=
github.com/spf13/cobra v1.1.1/go.mod h1:WnodtKOvamDL/PwE2M4iKs8aMDBZ5Q5klgD3qfVJQMI=
github.com/spf13/cobra v1.4.0 h1:y+wJpx64xcgO1V+RcnwW0LEHxTKRi2ZDPSBjWnrg88Q=
github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g=
github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU=
github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk=
github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo=
Expand Down
4 changes: 0 additions & 4 deletions server/mock/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,6 @@ func (kv kvStore) Delete(key []byte) {
delete(kv.store, string(key))
}

func (kv kvStore) Prefetch(key []byte, forSet bool) (hits, misses int, value []byte) {
return 0, 0, nil
}

func (kv kvStore) Prefix(prefix []byte) sdk.KVStore {
panic("not implemented")
}
Expand Down
1 change: 0 additions & 1 deletion server/mock/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func TestStore(t *testing.T) {
require.False(t, store.Has(k))
store.Set(k, v)
require.True(t, store.Has(k))
store.Prefetch(k, false)
require.Equal(t, v, store.Get(k))
store.Delete(k)
require.False(t, store.Has(k))
Expand Down
2 changes: 1 addition & 1 deletion simapp/ante_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func NewAnteHandler(
// ante.NewDeductFeeDecorator(ak, bankKeeper),
ante.NewSigGasConsumeDecorator(ak, sigGasConsumer),
ante.NewSigVerificationDecorator(ak, signModeHandler),
ante.NewIncrementSequenceDecorator(ak, bankKeeper),
ante.NewIncrementSequenceDecorator(ak),
ibcante.NewAnteDecorator(channelKeeper),
)
}
9 changes: 0 additions & 9 deletions store/cachekv/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,6 @@ func (store *Store) Delete(key []byte) {
store.setCacheValue(key, nil, true, true)
}

// Prefetch implements types.KVStore.
func (store *Store) Prefetch(key []byte, forSet bool) (hits, misses int, value []byte) {
defer telemetry.MeasureSince(time.Now(), "store", "cachekv", "prefetch")

// do not update cache
types.AssertValidKey(key)
return store.parent.Prefetch(key, forSet)
}

// Implements Cachetypes.KVStore.
func (store *Store) Write() {
store.mtx.Lock()
Expand Down
1 change: 0 additions & 1 deletion store/cachekv/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ func TestCacheKVStore(t *testing.T) {
// put something in mem and in cache
mem.Set(keyFmt(1), valFmt(1))
st.Set(keyFmt(1), valFmt(1))
st.Prefetch(keyFmt(1), false)
require.Equal(t, valFmt(1), st.Get(keyFmt(1)))

// update it in cache, shoudn't change mem
Expand Down
21 changes: 1 addition & 20 deletions store/cachemulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cachemulti
import (
"fmt"
"io"
"sync"

tmdb "github.com/line/tm-db/v2"

Expand Down Expand Up @@ -138,26 +137,8 @@ func (cms Store) GetStoreType() types.StoreType {
// Write calls Write on each underlying store.
func (cms Store) Write() {
cms.db.Write()
var wg sync.WaitGroup
var panicMsg interface{}
for _, store := range cms.stores {
wg.Add(1)
go func(s types.CacheWrap) {
defer func() {
if msg := recover(); msg != nil {
if panicMsg == nil {
panicMsg = msg
}
}
wg.Done()
}()

s.Write()
}(store)
}
wg.Wait()
if panicMsg != nil {
panic(panicMsg)
store.Write()
}
}

Expand Down
9 changes: 0 additions & 9 deletions store/dbadapter/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,6 @@ func (dsa Store) Delete(key []byte) {
}
}

// Prefetch wraps the underlying DB's Get method panicing on error.
func (dsa Store) Prefetch(key []byte, forSet bool) (hits, misses int, value []byte) {
v, err := dsa.DB.Get(key)
if err != nil {
return 0, 0, nil
}
return 1, 1, v
}

// Iterator wraps the underlying DB's Iterator method panicing on error.
func (dsa Store) Iterator(start, end []byte) types.Iterator {
iter, err := dsa.DB.Iterator(start, end)
Expand Down
2 changes: 0 additions & 2 deletions store/dbadapter/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ func TestAccessors(t *testing.T) {
retFoo := []byte("xxx")
mockDB.EXPECT().Get(gomock.Eq(key)).Times(1).Return(retFoo, nil)
require.True(t, bytes.Equal(retFoo, store.Get(key)))
mockDB.EXPECT().Get(gomock.Eq(key)).Times(1).Return(retFoo, nil)
store.Prefetch(key, false)

mockDB.EXPECT().Get(gomock.Eq(key)).Times(1).Return(nil, errFoo)
require.Panics(t, func() { store.Get(key) })
Expand Down
6 changes: 0 additions & 6 deletions store/gaskv/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,6 @@ func (gs *Store) Delete(key []byte) {
gs.parent.Delete(key)
}

// Implements KVStore.
func (gs *Store) Prefetch(key []byte, forSet bool) (hits, misses int, value []byte) {
defer telemetry.MeasureSince(time.Now(), "store", "gaskv", "load")
return gs.parent.Prefetch(key, forSet)
}

// Iterator implements the KVStore interface. It returns an iterator which
// incurs a flat gas cost for seeking to the first key/value pair and a variable
// gas cost based on the current value's length if the iterator is valid.
Expand Down
1 change: 0 additions & 1 deletion store/gaskv/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ func TestGasKVStoreBasic(t *testing.T) {
require.Panics(t, func() { st.Set([]byte(""), []byte("value")) }, "setting an empty key should panic")

require.Empty(t, st.Get(keyFmt(1)), "Expected `key1` to be empty")
st.Prefetch(keyFmt(1), false)
st.Set(keyFmt(1), valFmt(1))
require.Equal(t, valFmt(1), st.Get(keyFmt(1)))
st.Delete(keyFmt(1))
Expand Down
24 changes: 8 additions & 16 deletions store/iavl/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ const (

// Metrics contains metrics exposed by this package.
type Metrics struct {
IAVLCacheHits metrics.Gauge
IAVLCacheMisses metrics.Gauge
IAVLCacheEntries metrics.Gauge
IAVLCacheBytes metrics.Gauge
IAVLCachePeakBytes metrics.Gauge
IAVLCacheHits metrics.Gauge
IAVLCacheMisses metrics.Gauge
IAVLCacheEntries metrics.Gauge
IAVLCacheBytes metrics.Gauge
}

// PrometheusMetrics returns Metrics build using Prometheus client library.
Expand Down Expand Up @@ -55,23 +54,16 @@ func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics {
Name: "bytes_size",
Help: "Cache bytes size of the iavl cache",
}, labels).With(labelsAndValues...),
IAVLCachePeakBytes: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
Namespace: namespace,
Subsystem: MetricsSubsystem,
Name: "peak_bytes_size",
Help: "Peak cache bytes size of the iavl cache",
}, labels).With(labelsAndValues...),
}
}

// NopMetrics returns no-op Metrics.
func NopMetrics() *Metrics {
return &Metrics{
IAVLCacheHits: discard.NewGauge(),
IAVLCacheMisses: discard.NewGauge(),
IAVLCacheEntries: discard.NewGauge(),
IAVLCacheBytes: discard.NewGauge(),
IAVLCachePeakBytes: discard.NewGauge(),
IAVLCacheHits: discard.NewGauge(),
IAVLCacheMisses: discard.NewGauge(),
IAVLCacheEntries: discard.NewGauge(),
IAVLCacheBytes: discard.NewGauge(),
}
}

Expand Down
Loading

0 comments on commit c431caf

Please sign in to comment.