Skip to content

Commit

Permalink
feat: proto for oracle upgrade and its skeleton (#577)
Browse files Browse the repository at this point in the history
Co-authored-by: audtlr24 <audtlr24@gmail.com>
Co-authored-by: Youngjoon Lee <taxihighway@gmail.com>
Co-authored-by: Youngjoon Lee <yjlee@medibloc.org>
  • Loading branch information
4 people authored Jan 3, 2023
1 parent c8132b2 commit 2156e2e
Show file tree
Hide file tree
Showing 14 changed files with 2,587 additions and 335 deletions.
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"

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

0 comments on commit 2156e2e

Please sign in to comment.