Skip to content
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

perf: internal objects optimization (BaseAccount, Balance & Supply) #320

Merged
merged 6 commits into from
Sep 10, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
* (wasm) [\#253](https://github.com/line/lfb-sdk/pull/253) remove MaxGas const
* (wasm) [\#254](https://github.com/line/lfb-sdk/pull/254) Specify wasm event types
* (x) [\#255](https://github.com/line/lfb-sdk/pull/255) Remove legacy from modules
* (perf) [\#320](https:/github.com/line/lfb-sdk/pull/320) internal objects optimization (BaseAccount, Balance & Supply)

### Bug Fixes
* (test) [\#92](https://github.com/line/lfb-sdk/pull/92) Fix SendToModuleAccountTest
Expand Down
273 changes: 127 additions & 146 deletions docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -440,21 +440,10 @@

- [Msg](#lfb.crisis.v1beta1.Msg)

- [lfb/crypto/ed25519/keys.proto](#lfb/crypto/ed25519/keys.proto)
- [PrivKey](#lfb.crypto.ed25519.PrivKey)
- [PubKey](#lfb.crypto.ed25519.PubKey)

- [lfb/crypto/multisig/keys.proto](#lfb/crypto/multisig/keys.proto)
- [LegacyAminoPubKey](#lfb.crypto.multisig.LegacyAminoPubKey)

- [lfb/crypto/multisig/v1beta1/multisig.proto](#lfb/crypto/multisig/v1beta1/multisig.proto)
- [CompactBitArray](#lfb.crypto.multisig.v1beta1.CompactBitArray)
- [MultiSignature](#lfb.crypto.multisig.v1beta1.MultiSignature)

- [lfb/crypto/secp256k1/keys.proto](#lfb/crypto/secp256k1/keys.proto)
- [PrivKey](#lfb.crypto.secp256k1.PrivKey)
- [PubKey](#lfb.crypto.secp256k1.PubKey)

- [lfb/distribution/v1beta1/distribution.proto](#lfb/distribution/v1beta1/distribution.proto)
- [CommunityPoolSpendProposal](#lfb.distribution.v1beta1.CommunityPoolSpendProposal)
- [CommunityPoolSpendProposalWithDeposit](#lfb.distribution.v1beta1.CommunityPoolSpendProposalWithDeposit)
Expand Down Expand Up @@ -4695,6 +4684,130 @@ trusted validator set at the TrustedHeight.



<a name="ibc.lightclients.ostracon.v1.Misbehaviour"></a>

### Misbehaviour
Misbehaviour is a wrapper over two conflicting Headers
that implements Misbehaviour interface expected by ICS-02


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `client_id` | [string](#string) | | |
| `header_1` | [Header](#ibc.lightclients.ostracon.v1.Header) | | |
| `header_2` | [Header](#ibc.lightclients.ostracon.v1.Header) | | |





<!-- end messages -->

<!-- end enums -->

<!-- end HasExtensions -->

<!-- end services -->



<a name="ibc/lightclients/ostracon/v1/ostracon.proto"></a>
<p align="right"><a href="#top">Top</a></p>

## ibc/lightclients/ostracon/v1/ostracon.proto



<a name="ibc.lightclients.ostracon.v1.ClientState"></a>

### ClientState
ClientState from Ostracon tracks the current validator set, latest height,
and a possible frozen height.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `chain_id` | [string](#string) | | |
| `trust_level` | [Fraction](#ibc.lightclients.ostracon.v1.Fraction) | | |
| `trusting_period` | [google.protobuf.Duration](#google.protobuf.Duration) | | duration of the period since the LastestTimestamp during which the submitted headers are valid for upgrade |
| `unbonding_period` | [google.protobuf.Duration](#google.protobuf.Duration) | | duration of the staking unbonding period |
| `max_clock_drift` | [google.protobuf.Duration](#google.protobuf.Duration) | | defines how much new (untrusted) header's Time can drift into the future. |
| `frozen_height` | [ibc.core.client.v1.Height](#ibc.core.client.v1.Height) | | Block height when the client was frozen due to a misbehaviour |
| `latest_height` | [ibc.core.client.v1.Height](#ibc.core.client.v1.Height) | | Latest height the client was updated to |
| `proof_specs` | [ics23.ProofSpec](#ics23.ProofSpec) | repeated | Proof specifications used in verifying counterparty state |
| `upgrade_path` | [string](#string) | repeated | Path at which next upgraded client will be committed. Each element corresponds to the key for a single CommitmentProof in the chained proof. NOTE: ClientState must stored under `{upgradePath}/{upgradeHeight}/clientState` ConsensusState must be stored under `{upgradepath}/{upgradeHeight}/consensusState` For SDK chains using the default upgrade module, upgrade_path should be []string{"upgrade", "upgradedIBCState"}` |
| `allow_update_after_expiry` | [bool](#bool) | | This flag, when set to true, will allow governance to recover a client which has expired |
| `allow_update_after_misbehaviour` | [bool](#bool) | | This flag, when set to true, will allow governance to unfreeze a client whose chain has experienced a misbehaviour event |






<a name="ibc.lightclients.ostracon.v1.ConsensusState"></a>

### ConsensusState
ConsensusState defines the consensus state from Ostracon.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `timestamp` | [google.protobuf.Timestamp](#google.protobuf.Timestamp) | | timestamp that corresponds to the block height in which the ConsensusState was stored. |
| `root` | [ibc.core.commitment.v1.MerkleRoot](#ibc.core.commitment.v1.MerkleRoot) | | commitment root (i.e app hash) |
| `next_validators_hash` | [bytes](#bytes) | | |






<a name="ibc.lightclients.ostracon.v1.Fraction"></a>

### Fraction
Fraction defines the protobuf message type for tmmath.Fraction that only supports positive values.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `numerator` | [uint64](#uint64) | | |
| `denominator` | [uint64](#uint64) | | |






<a name="ibc.lightclients.ostracon.v1.Header"></a>

### Header
Header defines the Ostracon client consensus Header.
It encapsulates all the information necessary to update from a trusted
Ostracon ConsensusState. The inclusion of TrustedHeight and
TrustedValidators allows this update to process correctly, so long as the
ConsensusState for the TrustedHeight exists, this removes race conditions
among relayers The SignedHeader and ValidatorSet are the new untrusted update
fields for the client. The TrustedHeight is the height of a stored
ConsensusState on the client that will be used to verify the new untrusted
header. The Trusted ConsensusState must be within the unbonding period of
current time in order to correctly verify, and the TrustedValidators must
hash to TrustedConsensusState.NextValidatorsHash since that is the last
trusted validator set at the TrustedHeight.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `signed_header` | [ostracon.types.SignedHeader](#ostracon.types.SignedHeader) | | |
| `validator_set` | [ostracon.types.ValidatorSet](#ostracon.types.ValidatorSet) | | |
| `voter_set` | [ostracon.types.VoterSet](#ostracon.types.VoterSet) | | |
| `trusted_height` | [ibc.core.client.v1.Height](#ibc.core.client.v1.Height) | | |
| `trusted_validators` | [ostracon.types.ValidatorSet](#ostracon.types.ValidatorSet) | | |
| `trusted_voters` | [ostracon.types.VoterSet](#ostracon.types.VoterSet) | | |






<a name="ibc.lightclients.ostracon.v1.Misbehaviour"></a>

### Misbehaviour
Expand Down Expand Up @@ -5057,7 +5170,9 @@ type for additional functionality (e.g. vesting).
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `address` | [string](#string) | | |
| `pub_key` | [google.protobuf.Any](#google.protobuf.Any) | | |
| `ed25519_pub_key` | [lfb.crypto.ed25519.PubKey](#lfb.crypto.ed25519.PubKey) | | |
| `secp256k1_pub_key` | [lfb.crypto.secp256k1.PubKey](#lfb.crypto.secp256k1.PubKey) | | |
| `multisig_pub_key` | [lfb.crypto.multisig.LegacyAminoPubKey](#lfb.crypto.multisig.LegacyAminoPubKey) | | |
| `sequence` | [uint64](#uint64) | | |


Expand Down Expand Up @@ -6815,90 +6930,6 @@ Msg defines the bank Msg service.



<a name="lfb/crypto/ed25519/keys.proto"></a>
<p align="right"><a href="#top">Top</a></p>

## lfb/crypto/ed25519/keys.proto



<a name="lfb.crypto.ed25519.PrivKey"></a>

### PrivKey
PrivKey defines a ed25519 private key.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `key` | [bytes](#bytes) | | |






<a name="lfb.crypto.ed25519.PubKey"></a>

### PubKey
PubKey defines a ed25519 public key
Key is the compressed form of the pubkey. The first byte depends is a 0x02 byte
if the y-coordinate is the lexicographically largest of the two associated with
the x-coordinate. Otherwise the first byte is a 0x03.
This prefix is followed with the x-coordinate.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `key` | [bytes](#bytes) | | |





<!-- end messages -->

<!-- end enums -->

<!-- end HasExtensions -->

<!-- end services -->



<a name="lfb/crypto/multisig/keys.proto"></a>
<p align="right"><a href="#top">Top</a></p>

## lfb/crypto/multisig/keys.proto



<a name="lfb.crypto.multisig.LegacyAminoPubKey"></a>

### LegacyAminoPubKey
LegacyAminoPubKey specifies a public key type
which nests multiple public keys and a threshold,
it uses legacy amino address rules.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `threshold` | [uint32](#uint32) | | |
| `public_keys` | [google.protobuf.Any](#google.protobuf.Any) | repeated | |





<!-- end messages -->

<!-- end enums -->

<!-- end HasExtensions -->

<!-- end services -->



<a name="lfb/crypto/multisig/v1beta1/multisig.proto"></a>
<p align="right"><a href="#top">Top</a></p>

Expand Down Expand Up @@ -6941,56 +6972,6 @@ signed and with which modes.



<!-- end messages -->

<!-- end enums -->

<!-- end HasExtensions -->

<!-- end services -->



<a name="lfb/crypto/secp256k1/keys.proto"></a>
<p align="right"><a href="#top">Top</a></p>

## lfb/crypto/secp256k1/keys.proto



<a name="lfb.crypto.secp256k1.PrivKey"></a>

### PrivKey
PrivKey defines a secp256k1 private key.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `key` | [bytes](#bytes) | | |






<a name="lfb.crypto.secp256k1.PubKey"></a>

### PubKey
PubKey defines a secp256k1 public key
Key is the compressed form of the pubkey. The first byte depends is a 0x02 byte
if the y-coordinate is the lexicographically largest of the two associated with
the x-coordinate. Otherwise the first byte is a 0x03.
This prefix is followed with the x-coordinate.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `key` | [bytes](#bytes) | | |





<!-- end messages -->

<!-- end enums -->
Expand Down
15 changes: 11 additions & 4 deletions proto/lfb/auth/v1beta1/auth.proto
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
syntax = "proto3";
package lfb.auth.v1beta1;

import "lfb/crypto/ed25519/keys.proto";
import "lfb/crypto/multisig/keys.proto";
import "lfb/crypto/secp256k1/keys.proto";
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "google/protobuf/any.proto";
iproudhon marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -17,10 +20,14 @@ message BaseAccount {

option (cosmos_proto.implements_interface) = "AccountI";

string address = 1;
google.protobuf.Any pub_key = 2
[(gogoproto.jsontag) = "public_key,omitempty", (gogoproto.moretags) = "yaml:\"public_key\""];
uint64 sequence = 3;
string address = 1;
lfb.crypto.ed25519.PubKey ed25519_pub_key = 2
[(gogoproto.jsontag) = "ed25519_public_key,omitempty", (gogoproto.moretags) = "yaml:\"ed25519_public_key\""];
lfb.crypto.secp256k1.PubKey secp256k1_pub_key = 3
[(gogoproto.jsontag) = "secp256k1_public_key,omitempty", (gogoproto.moretags) = "yaml:\"secp256k1_public_key\""];
lfb.crypto.multisig.LegacyAminoPubKey multisig_pub_key = 4
[(gogoproto.jsontag) = "multisig_public_key,omitempty", (gogoproto.moretags) = "yaml:\"multisig_public_key\""];
uint64 sequence = 5;
}

// ModuleAccount defines an account for modules that holds coins on a pool.
Expand Down
6 changes: 3 additions & 3 deletions proto/lfb/gov/v1beta1/gov.proto
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ enum ProposalStatus {
message TallyResult {
option (gogoproto.equal) = true;

string yes = 1 [(gogoproto.customtype) = "github.com/line/lfb-sdk/types.Int", (gogoproto.nullable) = false];
string abstain = 2 [(gogoproto.customtype) = "github.com/line/lfb-sdk/types.Int", (gogoproto.nullable) = false];
string no = 3 [(gogoproto.customtype) = "github.com/line/lfb-sdk/types.Int", (gogoproto.nullable) = false];
string yes = 1 [(gogoproto.customtype) = "github.com/line/lfb-sdk/types.Int", (gogoproto.nullable) = false];
string abstain = 2 [(gogoproto.customtype) = "github.com/line/lfb-sdk/types.Int", (gogoproto.nullable) = false];
string no = 3 [(gogoproto.customtype) = "github.com/line/lfb-sdk/types.Int", (gogoproto.nullable) = false];
string no_with_veto = 4 [
(gogoproto.customtype) = "github.com/line/lfb-sdk/types.Int",
(gogoproto.nullable) = false,
Expand Down
6 changes: 2 additions & 4 deletions proto/lfb/staking/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,8 @@ message MsgEditValidator {
// it's not mandatory to update. If not updated, the deserialized rate will be
// zero with no way to distinguish if an update was intended.
// REF: #2373
string commission_rate = 3 [
(gogoproto.customtype) = "github.com/line/lfb-sdk/types.Dec",
(gogoproto.moretags) = "yaml:\"commission_rate\""
];
string commission_rate = 3
[(gogoproto.customtype) = "github.com/line/lfb-sdk/types.Dec", (gogoproto.moretags) = "yaml:\"commission_rate\""];
string min_self_delegation = 4 [
(gogoproto.customtype) = "github.com/line/lfb-sdk/types.Int",
(gogoproto.moretags) = "yaml:\"min_self_delegation\""
Expand Down
5 changes: 2 additions & 3 deletions x/auth/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,13 @@ func (ak AccountKeeper) decodeAccount(bz []byte) types.AccountI {

// MarshalAccount protobuf serializes an Account interface
func (ak AccountKeeper) MarshalAccount(accountI types.AccountI) ([]byte, error) { // nolint:interfacer
return ak.cdc.MarshalInterface(accountI)
return types.MarshalAccountX(ak.cdc, accountI)
}

// UnmarshalAccount returns an Account interface from raw encoded account
// bytes of a Proto-based Account type
func (ak AccountKeeper) UnmarshalAccount(bz []byte) (types.AccountI, error) {
var acc types.AccountI
return acc, ak.cdc.UnmarshalInterface(bz, &acc)
return types.UnmarshalAccountX(ak.cdc, bz)
}

// GetCodec return codec.Marshaler object used by the keeper
Expand Down
Loading