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

chore: rename ApproveOracleRegistration to reuse #580

Merged
merged 38 commits into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 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
12f0e02
feat: add upgrade oracle tx cli
audtlr24 Dec 27, 2022
c634f6f
Merge remote-tracking branch 'origin/ft/570/upgrade-endblocker' into …
audtlr24 Dec 27, 2022
6ebe8b6
feat: add upgrade oracle keeper
audtlr24 Dec 27, 2022
f290bf2
feat: add test code for oracle upgrade
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
b7a94d9
Merge remote-tracking branch 'origin/ft/575/upgrade-proto' into ft/57…
audtlr24 Dec 28, 2022
9630dfb
fix
audtlr24 Dec 28, 2022
db97922
chore: rename ApproveOracleRegistration to reuse
Dec 28, 2022
159a4fe
fix
audtlr24 Dec 30, 2022
41d0d4b
fix
audtlr24 Jan 2, 2023
272412f
rename var
Jan 3, 2023
7ed8894
Update x/oracle/keeper/upgrade_test.go
audtlr24 Jan 3, 2023
e992219
Merge branch 'ft/571/upgrade-oracle-tx' into ft/na/rename-approve-ora…
0xHansLee Jan 3, 2023
19d1163
Merge remote-tracking branch 'origin/main' into ft/na/rename-approve-…
Jan 4, 2023
b283a3e
fix
Jan 4, 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
12 changes: 5 additions & 7 deletions proto/panacea/oracle/v2/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ message MsgRegisterOracleResponse {

// MsgApproveOracleRegistration defines the Msg/ApproveOracleRegistration
message MsgApproveOracleRegistration {
ApproveOracleRegistration approve_oracle_registration = 1;
ApprovalSharingOracleKey approval_sharing_oracle_key = 1;
Copy link

Choose a reason for hiding this comment

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

How about renaming like SharingOracleKeyApproval?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or.. MsgEncryptedOraclePrivKey..?

Copy link

Choose a reason for hiding this comment

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

Hmm.... I think that the ApprovalSharingOracleKey is more better. 😂

bytes signature = 2;
}

// ApproveOracleRegistration defines for oracle registration approval
message ApproveOracleRegistration {
// ApprovalSharingOracleKey defines approval for sharing oracle key encrypted with target oracle's node public key
message ApprovalSharingOracleKey {
string unique_id = 1;
string approver_oracle_address = 2;
string target_oracle_address = 3;
Expand Down Expand Up @@ -90,10 +90,8 @@ 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;
ApprovalSharingOracleKey approval_sharing_oracle_key = 1;
bytes signature = 2;
}

// MsgApproveOracleUpgradeResponse defines the response of Msg/ApproveOracleUpgrade
Expand Down
20 changes: 10 additions & 10 deletions x/oracle/keeper/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,21 @@ func (k Keeper) ApproveOracleRegistration(ctx sdk.Context, msg *types.MsgApprove
return sdkerrors.Wrapf(types.ErrApproveOracleRegistration, err.Error())
}

oracleRegistration, err := k.GetOracleRegistration(ctx, msg.ApproveOracleRegistration.UniqueId, msg.ApproveOracleRegistration.TargetOracleAddress)
oracleRegistration, err := k.GetOracleRegistration(ctx, msg.ApprovalSharingOracleKey.UniqueId, msg.ApprovalSharingOracleKey.TargetOracleAddress)
if err != nil {
return sdkerrors.Wrapf(types.ErrApproveOracleRegistration, err.Error())
}

oracleRegistration.EncryptedOraclePrivKey = msg.ApproveOracleRegistration.EncryptedOraclePrivKey
oracleRegistration.EncryptedOraclePrivKey = msg.ApprovalSharingOracleKey.EncryptedOraclePrivKey

// add an encrypted oracle private key to oracleRegistration
if err := k.SetOracleRegistration(ctx, oracleRegistration); err != nil {
return sdkerrors.Wrapf(types.ErrApproveOracleRegistration, err.Error())
}

newOracle := types.NewOracle(
msg.ApproveOracleRegistration.TargetOracleAddress,
msg.ApproveOracleRegistration.UniqueId,
msg.ApprovalSharingOracleKey.TargetOracleAddress,
msg.ApprovalSharingOracleKey.UniqueId,
oracleRegistration.Endpoint,
oracleRegistration.OracleCommissionRate,
oracleRegistration.OracleCommissionMaxRate,
Expand All @@ -79,8 +79,8 @@ func (k Keeper) ApproveOracleRegistration(ctx sdk.Context, msg *types.MsgApprove
ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeApproveOracleRegistration,
sdk.NewAttribute(types.AttributeKeyOracleAddress, msg.ApproveOracleRegistration.TargetOracleAddress),
sdk.NewAttribute(types.AttributeKeyUniqueID, msg.ApproveOracleRegistration.UniqueId),
sdk.NewAttribute(types.AttributeKeyOracleAddress, msg.ApprovalSharingOracleKey.TargetOracleAddress),
sdk.NewAttribute(types.AttributeKeyUniqueID, msg.ApprovalSharingOracleKey.UniqueId),
),
)

Expand All @@ -92,19 +92,19 @@ func (k Keeper) ApproveOracleRegistration(ctx sdk.Context, msg *types.MsgApprove
func (k Keeper) validateApproveOracleRegistration(ctx sdk.Context, msg *types.MsgApproveOracleRegistration) error {

params := k.GetParams(ctx)
targetOracleAddress := msg.ApproveOracleRegistration.TargetOracleAddress
targetOracleAddress := msg.ApprovalSharingOracleKey.TargetOracleAddress

// check unique id
if msg.ApproveOracleRegistration.UniqueId != params.UniqueId {
if msg.ApprovalSharingOracleKey.UniqueId != params.UniqueId {
return types.ErrInvalidUniqueID
}

// verify signature
if err := k.VerifyOracleSignature(ctx, msg.ApproveOracleRegistration, msg.Signature); err != nil {
if err := k.VerifyOracleSignature(ctx, msg.ApprovalSharingOracleKey, msg.Signature); err != nil {
return err
}

if msg.ApproveOracleRegistration.EncryptedOraclePrivKey == nil {
if msg.ApprovalSharingOracleKey.EncryptedOraclePrivKey == nil {
return fmt.Errorf("encrypted oracle private key is nil")
}

Expand Down
14 changes: 7 additions & 7 deletions x/oracle/keeper/oracle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,19 +264,19 @@ func (suite *oracleTestSuite) TestApproveOracleRegistrationSuccess() {
encryptedOraclePrivKey, err := btcec.Encrypt(suite.nodePubKey, suite.oraclePrivKey.Serialize())
suite.Require().NoError(err)

approveOracleRegistration := &types.ApproveOracleRegistration{
approvalSharingOracleKey := &types.ApprovalSharingOracleKey{
UniqueId: suite.uniqueID,
ApproverOracleAddress: suite.oracleAccAddr.String(),
TargetOracleAddress: suite.oracleAccAddr.String(),
EncryptedOraclePrivKey: encryptedOraclePrivKey,
}

approveOracleRegistrationBz, err := suite.Cdc.Marshaler.Marshal(approveOracleRegistration)
approveOracleRegistrationBz, err := suite.Cdc.Marshaler.Marshal(approvalSharingOracleKey)
suite.Require().NoError(err)
signature, err := suite.oraclePrivKey.Sign(approveOracleRegistrationBz)
suite.Require().NoError(err)

msgApproveOracleRegistration := types.NewMsgApproveOracleRegistration(approveOracleRegistration, signature.Serialize())
msgApproveOracleRegistration := types.NewMsgApproveOracleRegistration(approvalSharingOracleKey, signature.Serialize())

err = suite.OracleKeeper.ApproveOracleRegistration(ctx, msgApproveOracleRegistration)
suite.Require().NoError(err)
Expand All @@ -301,7 +301,7 @@ func (suite *oracleTestSuite) TestApproveOracleRegistrationSuccess() {

getOracleRegistration, err := suite.OracleKeeper.GetOracleRegistration(suite.Ctx, suite.uniqueID, suite.oracleAccAddr.String())
suite.Require().NoError(err)
suite.Require().Equal(approveOracleRegistration.EncryptedOraclePrivKey, getOracleRegistration.EncryptedOraclePrivKey)
suite.Require().Equal(approvalSharingOracleKey.EncryptedOraclePrivKey, getOracleRegistration.EncryptedOraclePrivKey)
}

func (suite *oracleTestSuite) TestApproveOracleRegistrationFailedInvalidUniqueID() {
Expand All @@ -326,7 +326,7 @@ func (suite *oracleTestSuite) TestApproveOracleRegistrationFailedInvalidUniqueID
encryptedOraclePrivKey, err := btcec.Encrypt(suite.nodePubKey, suite.oraclePrivKey.Serialize())
suite.Require().NoError(err)

approveOracleRegistration := &types.ApproveOracleRegistration{
approveOracleRegistration := &types.ApprovalSharingOracleKey{
UniqueId: "uniqueID2",
ApproverOracleAddress: suite.oracleAccAddr.String(),
TargetOracleAddress: suite.oracleAccAddr.String(),
Expand Down Expand Up @@ -365,7 +365,7 @@ func (suite *oracleTestSuite) TestApproveOracleRegistrationFailedInvalidSignatur
encryptedOraclePrivKey, err := btcec.Encrypt(suite.nodePubKey, suite.oraclePrivKey.Serialize())
suite.Require().NoError(err)

approveOracleRegistration := &types.ApproveOracleRegistration{
approveOracleRegistration := &types.ApprovalSharingOracleKey{
UniqueId: "uniqueID",
ApproverOracleAddress: suite.oracleAccAddr.String(),
TargetOracleAddress: suite.oracleAccAddr.String(),
Expand Down Expand Up @@ -412,7 +412,7 @@ func (suite *oracleTestSuite) TestApproveOracleRegistrationFailedAlreadyExistOra
encryptedOraclePrivKey, err := btcec.Encrypt(suite.nodePubKey, suite.oraclePrivKey.Serialize())
suite.Require().NoError(err)

approveOracleRegistration := &types.ApproveOracleRegistration{
approveOracleRegistration := &types.ApprovalSharingOracleKey{
UniqueId: "uniqueID",
ApproverOracleAddress: suite.oracleAccAddr.String(),
TargetOracleAddress: suite.oracleAccAddr.String(),
Expand Down
14 changes: 7 additions & 7 deletions x/oracle/types/message_oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ func (m *MsgRegisterOracle) GetSigners() []sdk.AccAddress {

var _ sdk.Msg = &MsgApproveOracleRegistration{}

func NewMsgApproveOracleRegistration(approve *ApproveOracleRegistration, signature []byte) *MsgApproveOracleRegistration {
func NewMsgApproveOracleRegistration(approve *ApprovalSharingOracleKey, signature []byte) *MsgApproveOracleRegistration {
return &MsgApproveOracleRegistration{
ApproveOracleRegistration: approve,
Signature: signature,
ApprovalSharingOracleKey: approve,
Signature: signature,
}
}

Expand All @@ -102,7 +102,7 @@ func (m *MsgApproveOracleRegistration) Type() string {
}

func (m *MsgApproveOracleRegistration) ValidateBasic() error {
if err := m.ApproveOracleRegistration.ValidateBasic(); err != nil {
if err := m.ApprovalSharingOracleKey.ValidateBasic(); err != nil {
return err
}

Expand All @@ -119,14 +119,14 @@ func (m *MsgApproveOracleRegistration) GetSignBytes() []byte {
}

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

func (m *ApproveOracleRegistration) ValidateBasic() error {
func (m *ApprovalSharingOracleKey) ValidateBasic() error {
if len(m.UniqueId) == 0 {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "uniqueID is empty")
}
Expand Down Expand Up @@ -268,7 +268,7 @@ func (m *MsgApproveOracleUpgrade) GetSignBytes() []byte {
}

func (m *MsgApproveOracleUpgrade) GetSigners() []sdk.AccAddress {
oracleAddress, err := sdk.AccAddressFromBech32(m.ApproverOracleAddress)
oracleAddress, err := sdk.AccAddressFromBech32(m.ApprovalSharingOracleKey.ApproverOracleAddress)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion x/oracle/types/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ func NewUpgradeOracle(msg *MsgUpgradeOracle) *OracleUpgrade {
TrustedBlockHash: msg.TrustedBlockHash,
}
}

func (m *OracleUpgrade) ValidateBasic() error {
if len(m.UniqueId) == 0 {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "uniqueID is empty")
Expand All @@ -174,6 +175,5 @@ func (m *OracleUpgrade) ValidateBasic() error {
if m.TrustedBlockHash == nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "trusted block hash should not be nil")
}

return nil
}
Loading