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

feat: proto for oracle upgrade and its skeleton #577

Merged
merged 28 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3893eae
feat: add extra commission rate flags to genoracle cmd
audtlr24 Dec 19, 2022
8330472
feat: add v2.1.0 upgrade handler (#552)
0xHansLee Dec 15, 2022
eda304c
ci: make actions work for main branch (#555)
Dec 16, 2022
fecab14
feat: add oracle upgrade proposal tx & cli
audtlr24 Dec 26, 2022
af4a238
feat: add test code
audtlr24 Dec 26, 2022
402eeb1
feat: add oracle upgrade proposal tx & cli
audtlr24 Dec 26, 2022
468a132
feat: add test code
audtlr24 Dec 26, 2022
31557d5
Merge remote-tracking branch 'origin/ft/569/oracle-upgrade-handler' i…
audtlr24 Dec 26, 2022
ec72841
feat: proto for oracle upgrade and its skeleton
Dec 26, 2022
8eec577
fix test
Dec 26, 2022
69bc58b
add event type of oracle upgrade
Dec 26, 2022
860223d
feat: add oracle upgrade to EndBlocker
audtlr24 Dec 26, 2022
909c3d8
add oracle upgrade key
Dec 27, 2022
07b94cc
fix
audtlr24 Dec 27, 2022
cb6b661
fix
audtlr24 Dec 27, 2022
1ee72d5
fix
audtlr24 Dec 27, 2022
34fee18
fix
audtlr24 Dec 27, 2022
660d959
Merge remote-tracking branch 'origin/ft/569/oracle-upgrade-handler' i…
audtlr24 Dec 27, 2022
61e8e4e
Merge remote-tracking branch 'origin/ft/570/upgrade-endblocker' into …
Dec 27, 2022
c66ff61
remove duplicated grpc query
Dec 27, 2022
f73a2ca
use the same request/response message for approval of oracle upgrade
Dec 28, 2022
44a3f47
fix
Dec 28, 2022
442479b
Revert "fix"
Dec 28, 2022
5da5d80
Revert "use the same request/response message for approval of oracle …
Dec 28, 2022
649e9d3
Merge remote-tracking branch 'origin/main' into ft/575/upgrade-proto
Jan 3, 2023
2a5b6c4
fix
Jan 3, 2023
ca8b563
fix
Jan 3, 2023
a9f08d6
Merge branch 'main' into ft/575/upgrade-proto
0xHansLee Jan 3, 2023
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
8 changes: 3 additions & 5 deletions client/docs/statik/statik.go

Large diffs are not rendered by default.

22 changes: 21 additions & 1 deletion proto/panacea/oracle/v2/oracle.proto
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,31 @@ message OracleRegistration {
bytes encrypted_oracle_priv_key = 11;
}

// OracleUpgrade defines the states of oracle upgrade
message OracleUpgrade {
string unique_id = 1;
string oracle_address = 2;
// Node public key is a pair with a node private key which is generated in SGX by each oracle.
// This key is used to share the oracle private key from other oracles.
bytes node_pub_key = 3;
// Anyone can validate that the node key pair is generated in SGX using this node key remote report.
bytes node_pub_key_remote_report = 4;
// An oracle to be upgraded must report a trusted block info which was used to initialize its light client with a new version of oracle.
// Other oracles will validate whether this trusted block info is correct,
// in order to prevent malicious operators from making the oracle look at a malicious chain node.
// Other oracles don't have to worry about whether this block info was set by a malicious operator,
// because this message has to be generated inside SGX.
// Also, after this oracle upgrade is complete, the light client is protected from malicious operators by SGX.
int64 trusted_block_height = 5;
bytes trusted_block_hash = 6;
bytes encrypted_oracle_priv_key = 7;
}

// OracleUpgradeInfo defines the info of oracle upgrade, which includes the target height of upgrade and unique ID of the new version of oracle
message OracleUpgradeInfo {
option (gogoproto.equal) = true;

string unique_id = 1;

int64 height = 2;
}
}
16 changes: 16 additions & 0 deletions proto/panacea/oracle/v2/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ service Query {
option (google.api.http).get = "/panacea/oracle/v2/oracle-upgrade-info";
}

// OracleUpgrade returns the information related to oracle upgrade
rpc OracleUpgrade(QueryOracleUpgradeRequest) returns (QueryOracleUpgradeResponse) {
option (google.api.http).get = "/panacea/oracle/v2/oracle-upgrades/{unique_id}/{oracle_address}";
}

// Params returns params of oracle module.
rpc Params(QueryOracleParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/panacea/oracle/v2/params";
Expand Down Expand Up @@ -95,6 +100,17 @@ message QueryOracleUpgradeInfoResponse {
OracleUpgradeInfo oracle_upgrade_info = 1;
}

// QueryOracleUpgradeRequest is the request type for the Query/OracleUpgrade RPC method.
message QueryOracleUpgradeRequest {
string unique_id = 1;
string oracle_address = 2;
}

// QueryOracleUpgradeResponse is the response type for the Query/OracleUpgrade RPC method.
message QueryOracleUpgradeResponse {
OracleUpgrade oracle_upgrade = 1;
}

// QueryOracleParamsRequest is the request type for the Query/OracleParams RPC method.
message QueryOracleParamsRequest {}

Expand Down
34 changes: 32 additions & 2 deletions proto/panacea/oracle/v2/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ service Msg {
// ApproveOracleRegistration defines a method to approve oracle registration
rpc ApproveOracleRegistration(MsgApproveOracleRegistration) returns (MsgApproveOracleRegistrationResponse);

// UpgradeOracle defines a method for upgrade of oracle.
// UpgradeOracleInfo defines a method to update oracle info
rpc UpdateOracleInfo(MsgUpdateOracleInfo) returns (MsgUpdateOracleInfoResponse);

// UpgradeOracle defines a method for upgrade of oracle
rpc UpgradeOracle(MsgUpgradeOracle) returns (MsgUpgradeOracleResponse);

// ApproveOracleUpgrade defines a method for approval of oracle upgrade
rpc ApproveOracleUpgrade(MsgApproveOracleUpgrade) returns (MsgApproveOracleUpgradeResponse);
}

// MsgRegisterOracle defines the Msg/RegisterOracle request type.
Expand Down Expand Up @@ -62,9 +68,33 @@ message MsgApproveOracleRegistrationResponse {
message MsgUpdateOracleInfo {
string oracle_address = 1; // panacea1.. account address
string endpoint = 2;
string oracle_commission_rate = 3 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",(gogoproto.nullable) = true];
string oracle_commission_rate = 3 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = true];
}

// MsgUpdateOracleInfoResponse defines the Msg/UpdateOracleInfo
message MsgUpdateOracleInfoResponse {
}

// MsgUpgradeOracle defines the Msg/UpgradeOracle
message MsgUpgradeOracle {
string unique_id = 1;
string oracle_address = 2; // panacea1.. account address
bytes node_pub_key = 3;
bytes node_pub_key_remote_report = 4;
int64 trusted_block_height = 5;
bytes trusted_block_hash = 6;
}

// MsgUpgradeOracleResponse defines the response of Msg/UpgradeOracle
message MsgUpgradeOracleResponse {}

// MsgApproveOracleUpgrade defines the Msg/ApproveOracleUpgrade
message MsgApproveOracleUpgrade {
string unique_id = 1;
string approver_oracle_address = 2;
string target_oracle_address = 3;
bytes encrypted_oracle_priv_key = 4;
}

// MsgApproveOracleUpgradeResponse defines the response of Msg/ApproveOracleUpgrade
message MsgApproveOracleUpgradeResponse {}
5 changes: 5 additions & 0 deletions x/oracle/keeper/grpc_query_oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,8 @@ func (k Keeper) Params(goCtx context.Context, _ *types.QueryOracleParamsRequest)
params := k.GetParams(sdk.UnwrapSDKContext(goCtx))
return &types.QueryParamsResponse{Params: &params}, nil
}

func (k Keeper) OracleUpgrade(goCtx context.Context, request *types.QueryOracleUpgradeRequest) (*types.QueryOracleUpgradeResponse, error) {
// TODO: Implementation
return &types.QueryOracleUpgradeResponse{}, nil
}
10 changes: 10 additions & 0 deletions x/oracle/keeper/msg_server_oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,13 @@ func (m msgServer) UpdateOracleInfo(goCtx context.Context, msg *types.MsgUpdateO

return &types.MsgUpdateOracleInfoResponse{}, nil
}

func (m msgServer) UpgradeOracle(goCtx context.Context, msg *types.MsgUpgradeOracle) (*types.MsgUpgradeOracleResponse, error) {
// TODO: Implementation
return &types.MsgUpgradeOracleResponse{}, nil
}

func (m msgServer) ApproveOracleUpgrade(goCtx context.Context, msg *types.MsgApproveOracleUpgrade) (*types.MsgApproveOracleUpgradeResponse, error) {
// TODO: Implementation
return &types.MsgApproveOracleUpgradeResponse{}, nil
}
7 changes: 7 additions & 0 deletions x/oracle/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,20 @@ func RegisterCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&MsgRegisterOracle{}, "oracle/RegisterOracle", nil)
cdc.RegisterConcrete(&MsgApproveOracleRegistration{}, "oracle/ApproveOracleRegistration", nil)
cdc.RegisterConcrete(&MsgUpdateOracleInfo{}, "oracle/UpdateOracleInfo", nil)
cdc.RegisterConcrete(&MsgUpgradeOracle{}, "oracle/UpgradeOracle", nil)
cdc.RegisterConcrete(&MsgApproveOracleUpgrade{}, "oracle/ApproveOracleUpgrade", nil)
}

func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgRegisterOracle{},
&MsgApproveOracleRegistration{},
&MsgUpdateOracleInfo{},
&MsgUpgradeOracle{},
&MsgApproveOracleUpgrade{},
)
registry.RegisterImplementations((*govtypes.Content)(nil),
&OracleUpgradeProposal{},
)
registry.RegisterImplementations((*govtypes.Content)(nil),
&OracleUpgradeProposal{},
Expand Down
2 changes: 2 additions & 0 deletions x/oracle/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package types
const (
EventTypeRegistration = "oracle_registration"
EventTypeApproveOracleRegistration = "approve_oracle_registration"
EventTypeUpgrade = "oracle_upgrade"
EventTypeApproveOracleUpgrade = "approve_oracle_upgrade"
Comment on lines +6 to +7
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, add separate event for oracle upgrade. This event type will be used in oracle side.


AttributeKeyUniqueID = "unique_id"
AttributeKeyOracleAddress = "oracle_address"
Expand Down
5 changes: 5 additions & 0 deletions x/oracle/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var (
OraclesKey = []byte{0x01}
OracleRegistrationKey = []byte{0x02}
OracleUpgradeInfoKey = []byte{0x03}
OracleUpgradeKey = []byte{0x04}

IndexSeparator = []byte{0xFF}
)
Expand All @@ -40,6 +41,10 @@ func GetOracleRegistrationKey(uniqueID string, address sdk.AccAddress) []byte {
return append(OracleRegistrationKey, CombineKeys([]byte(uniqueID), address)...)
}

func GetOracleUpgradeKey(uniqueID string, address sdk.AccAddress) []byte {
return append(OracleUpgradeKey, CombineKeys([]byte(uniqueID), address)...)
}

func CombineKeys(keys ...[]byte) []byte {
return bytes.Join(keys, IndexSeparator)
}
52 changes: 52 additions & 0 deletions x/oracle/types/message_oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,55 @@ func (m *MsgUpdateOracleInfo) GetSigners() []sdk.AccAddress {
}
return []sdk.AccAddress{oracleAddress}
}

func (m *MsgUpgradeOracle) Route() string {
return RouterKey
}

func (m *MsgUpgradeOracle) Type() string {
return "UpgradeOracle"
}

func (m *MsgUpgradeOracle) ValidateBasic() error {
// TODO: Implementation
return nil
}

func (m *MsgUpgradeOracle) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(m)
return sdk.MustSortJSON(bz)
}

func (m *MsgUpgradeOracle) GetSigners() []sdk.AccAddress {
oracleAddress, err := sdk.AccAddressFromBech32(m.OracleAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{oracleAddress}
}

func (m *MsgApproveOracleUpgrade) Route() string {
return RouterKey
}

func (m *MsgApproveOracleUpgrade) Type() string {
return "ApproveOracleUpgrade"
}

func (m *MsgApproveOracleUpgrade) ValidateBasic() error {
// TODO: Implementation
return nil
}

func (m *MsgApproveOracleUpgrade) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(m)
return sdk.MustSortJSON(bz)
}

func (m *MsgApproveOracleUpgrade) GetSigners() []sdk.AccAddress {
oracleAddress, err := sdk.AccAddressFromBech32(m.ApproverOracleAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{oracleAddress}
}
Loading