Skip to content

Commit

Permalink
Merge branch 'main' into token
Browse files Browse the repository at this point in the history
  • Loading branch information
0Tech committed Jul 26, 2022
2 parents 4048634 + 253d07e commit f5249a8
Show file tree
Hide file tree
Showing 472 changed files with 83,717 additions and 4,002 deletions.
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ issues:
- text: "SA1019: codec.LegacyAmino is deprecated"
linters:
- staticcheck
- text: "SA1019: collection."
linters:
- staticcheck
max-issues-per-linter: 10000
max-same-issues: 10000

Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,16 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/foundation) [\#518](https://github.com/line/lbm-sdk/pull/518) add foundation treasury feature to x/foundation
* (x/foundation) [\#528](https://github.com/line/lbm-sdk/pull/528) add a feature of whitelist for /lbm.foundation.v1.MsgWithdrawFromTreasury
* (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

* (refactor) [\#493](https://github.com/line/lbm-sdk/pull/493) restructure x/consortium
* (server/grpc) [\#526](https://github.com/line/lbm-sdk/pull/526) add index field into TxResponse
* (cli) [\#535](https://github.com/line/lbm-sdk/pull/536) updated ostracon to v1.0.5; `unsafe-reset-all` command has been moved to the `ostracon` sub-command.
* (x/foundation) [\#597](https://github.com/line/lbm-sdk/pull/597) tidy up x/foundation

### Bug Fixes
* (x/wasm) [\#453](https://github.com/line/lbm-sdk/pull/453) modify wasm grpc query api path
Expand All @@ -65,6 +69,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Breaking Changes
* (proto) [\#564](https://github.com/line/lbm-sdk/pull/564) change gRPC path to original cosmos path
* (global) [\#603](https://github.com/line/lbm-sdk/pull/603) apply types/address.go from [email protected]

### Build, CI

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
2 changes: 1 addition & 1 deletion baseapp/accountwgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func newTestPrivKeys(num int) []*secp256k1.PrivKey {
func getAddrs(privs []*secp256k1.PrivKey) []sdk.AccAddress {
addrs := make([]sdk.AccAddress, 0, len(privs))
for _, priv := range privs {
addrs = append(addrs, sdk.BytesToAccAddress(priv.PubKey().Address()))
addrs = append(addrs, sdk.AccAddress(priv.PubKey().Address()))
}
return addrs
}
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
2 changes: 1 addition & 1 deletion baseapp/block_gas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func TestBaseApp_BlockGas(t *testing.T) {
require.Equal(t, []byte("ok"), okValue)
}
// check block gas is always consumed
baseGas := uint64(40043) // baseGas is the gas consumed before tx msg
baseGas := uint64(37352) // baseGas is the gas consumed before tx msg
expGasConsumed := addUint64Saturating(tc.gasToConsume, baseGas)
if expGasConsumed > txtypes.MaxGasWanted {
// capped by gasLimit
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
7 changes: 4 additions & 3 deletions client/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,16 @@ func readTxCommandFlags(clientCtx Context, flagSet *pflag.FlagSet) (Context, err
clientCtx = clientCtx.WithSignModeStr(signModeStr)
}

if clientCtx.FeeGranter == "" || flagSet.Changed(flags.FlagFeeAccount) {
if clientCtx.FeeGranter == nil || flagSet.Changed(flags.FlagFeeAccount) {
granter, _ := flagSet.GetString(flags.FlagFeeAccount)

if granter != "" {
err := sdk.ValidateAccAddress(granter)
granterAcc, err := sdk.AccAddressFromBech32(granter)
if err != nil {
return clientCtx, err
}
clientCtx = clientCtx.WithFeeGranterAddress(sdk.AccAddress(granter))

clientCtx = clientCtx.WithFeeGranterAddress(granterAcc)
}
}

Expand Down
16 changes: 8 additions & 8 deletions client/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,28 +335,28 @@ func (ctx Context) printOutput(out []byte) error {
// address is returned.
func GetFromFields(kr keyring.Keyring, from string, genOnly bool) (sdk.AccAddress, string, keyring.KeyType, error) {
if from == "" {
return "", "", 0, nil
return nil, "", 0, nil
}

if genOnly {
err := sdk.ValidateAccAddress(from)
addr, err := sdk.AccAddressFromBech32(from)
if err != nil {
return sdk.AccAddress(from), "", 0, errors.Wrap(err, "must provide a valid Bech32 address in generate-only mode")
return nil, "", 0, errors.Wrap(err, "must provide a valid Bech32 address in generate-only mode")
}

return sdk.AccAddress(from), "", 0, nil
return addr, "", 0, nil
}

var info keyring.Info
if err := sdk.ValidateAccAddress(from); err == nil {
info, err = kr.KeyByAddress(sdk.AccAddress(from))
if addr, err := sdk.AccAddressFromBech32(from); err == nil {
info, err = kr.KeyByAddress(addr)
if err != nil {
return sdk.AccAddress(from), "", 0, err
return nil, "", 0, err
}
} else {
info, err = kr.Key(from)
if err != nil {
return "", "", 0, err
return nil, "", 0, err
}
}

Expand Down
19 changes: 8 additions & 11 deletions client/debug/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,17 @@ $ %s debug addr link19wgf6ymq2ur6r59st95e04e49m69z4al4fc982
RunE: func(cmd *cobra.Command, args []string) error {

addrString := args[0]
var addrBytes []byte
var addr []byte

// try hex, then bech32
var err error
addrBytes, err = hex.DecodeString(addrString)
addr, err = hex.DecodeString(addrString)
if err != nil {
var err2 error
addrBytes, err2 = sdk.AccAddressToBytes(addrString)
addr, err2 = sdk.AccAddressFromBech32(addrString)
if err2 != nil {
var err3 error
addrBytes, err3 = sdk.ValAddressToBytes(addrString)
addr, err3 = sdk.ValAddressFromBech32(addrString)

if err3 != nil {
return fmt.Errorf("expected hex or bech32. Got errors: hex: %v, bech32 acc: %v, bech32 val: %v", err, err2, err3)
Expand All @@ -91,13 +91,10 @@ $ %s debug addr link19wgf6ymq2ur6r59st95e04e49m69z4al4fc982
}
}

accAddr := sdk.BytesToAccAddress(addrBytes)
valAddr := sdk.BytesToValAddress(addrBytes)

cmd.Println("Address Bytes:", addrBytes)
cmd.Printf("Address (hex): %X\n", addrBytes)
cmd.Printf("Bech32 Acc: %s\n", accAddr)
cmd.Printf("Bech32 Val: %s\n", valAddr)
cmd.Println("Address:", addr)
cmd.Printf("Address (hex): %X\n", addr)
cmd.Printf("Bech32 Acc: %s\n", sdk.AccAddress(addr))
cmd.Printf("Bech32 Val: %s\n", sdk.ValAddress(addr))
return nil
},
}
Expand Down
3 changes: 1 addition & 2 deletions client/keys/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,10 @@ func fetchKey(kb keyring.Keyring, keyref string) (keyring.Info, error) {
if err == nil || !sdkerr.IsOf(err, sdkerr.ErrIO, sdkerr.ErrKeyNotFound) {
return info, err
}
err = sdk.ValidateAccAddress(keyref)
accAddr, err := sdk.AccAddressFromBech32(keyref)
if err != nil {
return info, err
}
accAddr := sdk.AccAddress(keyref)

info, err = kb.KeyByAddress(accAddr)
return info, sdkerr.Wrap(err, "Invalid key")
Expand Down
4 changes: 1 addition & 3 deletions client/keys/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ func Test_multiSigKey_Properties(t *testing.T) {
require.Equal(t, "myMultisig", tmp.GetName())
require.Equal(t, keyring.TypeMulti, tmp.GetType())
require.Equal(t, "BDF0C827D34CA39919C7688EB5A95383C60B3471", tmp.GetPubKey().Address().String())
acc := tmp.GetAddress()
addrBytes, _ := sdk.AccAddressToBytes(acc.String())
require.Equal(t, "link1hhcvsf7nfj3ejxw8dz8tt22ns0rqkdr3rrh7xy", sdk.MustBech32ifyAddressBytes("link", addrBytes))
require.Equal(t, "link1hhcvsf7nfj3ejxw8dz8tt22ns0rqkdr3rrh7xy", sdk.MustBech32ifyAddressBytes("link", tmp.GetAddress()))
}

func Test_showKeysCmd(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion client/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (s *IntegrationTestSuite) TestQueryABCIHeight() {
req := abci.RequestQuery{
Path: fmt.Sprintf("store/%s/key", banktypes.StoreKey),
Height: tc.reqHeight,
Data: banktypes.CreateAccountBalancesPrefix(val.Address.Bytes()),
Data: banktypes.CreateAccountBalancesPrefix(val.Address),
Prove: true,
}

Expand Down
2 changes: 1 addition & 1 deletion client/rpc/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func validatorOutput(validator *octypes.Validator) (ValidatorOutput, error) {
}

return ValidatorOutput{
Address: sdk.BytesToConsAddress(validator.Address),
Address: sdk.ConsAddress(validator.Address),
PubKey: pk,
ProposerPriority: validator.ProposerPriority,
VotingPower: validator.VotingPower,
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
8 changes: 4 additions & 4 deletions crypto/keyring/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (i localInfo) GetPubKey() cryptotypes.PubKey {

// GetType implements Info interface
func (i localInfo) GetAddress() types.AccAddress {
return types.BytesToAccAddress(i.PubKey.Address())
return i.PubKey.Address().Bytes()
}

// GetType implements Info interface
Expand Down Expand Up @@ -117,7 +117,7 @@ func (i ledgerInfo) GetPubKey() cryptotypes.PubKey {

// GetAddress implements Info interface
func (i ledgerInfo) GetAddress() types.AccAddress {
return types.BytesToAccAddress(i.PubKey.Address())
return i.PubKey.Address().Bytes()
}

// GetPath implements Info interface
Expand Down Expand Up @@ -169,7 +169,7 @@ func (i offlineInfo) GetAlgo() hd.PubKeyType {

// GetAddress implements Info interface
func (i offlineInfo) GetAddress() types.AccAddress {
return types.BytesToAccAddress(i.PubKey.Address())
return i.PubKey.Address().Bytes()
}

// GetPath implements Info interface
Expand Down Expand Up @@ -222,7 +222,7 @@ func (i multiInfo) GetPubKey() cryptotypes.PubKey {

// GetAddress implements Info interface
func (i multiInfo) GetAddress() types.AccAddress {
return types.BytesToAccAddress(i.PubKey.Address())
return i.PubKey.Address().Bytes()
}

// GetPath implements Info interface
Expand Down
2 changes: 1 addition & 1 deletion crypto/keyring/keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ func (ks keystore) NewAccount(name string, mnemonic string, bip39Passphrase stri

// check if the a key already exists with the same address and return an error
// if found
address := sdk.BytesToAccAddress(privKey.PubKey().Address())
address := sdk.AccAddress(privKey.PubKey().Address())
if _, err := ks.KeyByAddress(address); err == nil {
return nil, fmt.Errorf("account with address %s already exists in keyring, delete the key first if you want to recreate it", address)
}
Expand Down
6 changes: 2 additions & 4 deletions crypto/keyring/keyring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ func TestKeyManagementKeyRing(t *testing.T) {
require.NotNil(t, err)
_, err = kb.KeyByAddress(accAddr(i2))
require.NoError(t, err)
addr := sdk.AccAddress("link1yxfu3fldlgux939t0gwaqs82l4x77v2kasa7jf")
err = sdk.ValidateAccAddress(addr.String())
addr, err := sdk.AccAddressFromBech32("link1yxfu3fldlgux939t0gwaqs82l4x77v2kasa7jf")
require.NoError(t, err)
_, err = kb.KeyByAddress(addr)
require.NotNil(t, err)
Expand Down Expand Up @@ -433,8 +432,7 @@ func TestInMemoryKeyManagement(t *testing.T) {
require.NotNil(t, err)
_, err = cstore.KeyByAddress(accAddr(i2))
require.NoError(t, err)
addr := sdk.AccAddress("link1yxfu3fldlgux939t0gwaqs82l4x77v2kasa7jf")
err = sdk.ValidateAccAddress(addr.String())
addr, err := sdk.AccAddressFromBech32("link1yxfu3fldlgux939t0gwaqs82l4x77v2kasa7jf")
require.NoError(t, err)
_, err = cstore.KeyByAddress(addr)
require.NotNil(t, err)
Expand Down
Loading

0 comments on commit f5249a8

Please sign in to comment.