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(ecocredit): custom bridging support for cancelling credits #1101

Merged
merged 24 commits into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c6e3045
feat: add proto msgs
aleem1314 May 12, 2022
ffd1801
add events proto message
aleem1314 May 12, 2022
3ab532b
feat: add msg implementation
aleem1314 May 12, 2022
f58dd43
chore: fix tests
aleem1314 May 17, 2022
b3db5f8
feat: add server tests
aleem1314 May 18, 2022
f7e1427
Merge branch 'master' into aleem/msg-bridge
aleem1314 May 18, 2022
cc59bca
chore: make proto-gen
aleem1314 May 18, 2022
5154273
chore: fix failing tests
aleem1314 May 18, 2022
c4e3a53
Update proto/regen/ecocredit/v1/events.proto
aleem1314 May 19, 2022
3ec9dbd
Update proto/regen/ecocredit/v1/tx.proto
aleem1314 May 19, 2022
733386a
Update x/ecocredit/client/tx.go
aleem1314 May 19, 2022
769dc29
Update x/ecocredit/core/msg_bridge.go
aleem1314 May 19, 2022
951d55d
Update proto/regen/ecocredit/v1/tx.proto
aleem1314 May 19, 2022
77c6685
chore: make proto-gen
aleem1314 May 19, 2022
4632dec
Update proto/regen/ecocredit/v1/events.proto
aleem1314 May 20, 2022
28f26d4
Update proto/regen/ecocredit/v1/tx.proto
aleem1314 May 20, 2022
2d99007
refactor: review changes
aleem1314 May 20, 2022
4cf6e8a
Update x/ecocredit/client/tx.go
aleem1314 May 23, 2022
5b24e33
Update x/ecocredit/core/msg_bridge.go
aleem1314 May 23, 2022
fca1881
Update x/ecocredit/server/testsuite/suite.go
aleem1314 May 23, 2022
cd90363
chore: review changes
aleem1314 May 24, 2022
20a47e6
Merge branch 'aleem/msg-bridge' of https://github.com/regen-network/r…
aleem1314 May 24, 2022
ca89998
Update x/ecocredit/core/msg_bridge.go
aleem1314 May 25, 2022
f8c3ddd
Merge branch 'master' into aleem/msg-bridge
aleem1314 May 25, 2022
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
989 changes: 844 additions & 145 deletions api/regen/ecocredit/v1/events.pulsar.go

Large diffs are not rendered by default.

1,773 changes: 1,485 additions & 288 deletions api/regen/ecocredit/v1/tx.pulsar.go

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions api/regen/ecocredit/v1/tx_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions proto/regen/ecocredit/v1/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ message EventCancel {

// amount is the decimal number of credits that have been cancelled.
string amount = 3;

// reason is any arbitary encoded data.
string reason = 4;
aleem1314 marked this conversation as resolved.
Show resolved Hide resolved
}

// EventUpdateClassAdmin is emitted when the admin address of a credit class is
Expand Down Expand Up @@ -159,3 +162,15 @@ message EventAddCreditType {
// abbreviation is the abbreviation of the credit type.
string abbreviation = 1;
}

// EventBridge is emitted emitted when credits are cancelled.
message EventBridge {
// bridge_target is the target chain.
string bridge_target = 1;

// bridge_recipient is the recipient address.
string bridge_recipient = 2;

// bridge_contract is the contract address.
string bridge_contract = 3;
}
aleem1314 marked this conversation as resolved.
Show resolved Hide resolved
24 changes: 24 additions & 0 deletions proto/regen/ecocredit/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ service Msg {
// UpdateProjectMetadata updates the project metadata
rpc UpdateProjectMetadata(MsgUpdateProjectMetadata)
returns (MsgUpdateProjectMetadataResponse);

// Bridge wraps MsgCancel and also emits bridge events.
rpc Bridge(MsgBridge) returns (MsgBridgeResponse);
aleem1314 marked this conversation as resolved.
Show resolved Hide resolved
}

// MsgCreateClass is the Msg/CreateClass request type.
Expand Down Expand Up @@ -321,6 +324,9 @@ message MsgCancel {
// credits are the credits being cancelled.
repeated CancelCredits credits = 2;

// reason is any arbitary encoded data, will be passed to an event.
string reason = 3;
aleem1314 marked this conversation as resolved.
Show resolved Hide resolved

// CancelCredits specifies a batch and the number of credits being cancelled.
message CancelCredits {

Expand Down Expand Up @@ -421,3 +427,21 @@ message MsgUpdateProjectMetadata {
// MsgUpdateProjectMetadataResponse is the Msg/UpdateProjectMetadataResponse
// response type.
message MsgUpdateProjectMetadataResponse {}

// MsgBridge is the Msg/Bridge request type.
message MsgBridge {
// MsgCancel is the MsgCancel message type.
MsgCancel msg_cancel = 1;
Copy link
Member

Choose a reason for hiding this comment

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

Looking at this again in more detail, I think it's preferable for us to not nest proto messages that are used as GRPC request messages like this. Ideally when defining msg server API endpoints, each can evolve independently (e.g. Bridge() and Cancel() should be able to evolve independently). So similar to how we always have explicitly separate MsgBridgeRepsonse and MsgCancelResponse, we should probably avoid embedding a MsgCancel field inside the MsgBridge message.

In terms of which fields from MsgCancel we need when a user is calling MsgBridge, I the following is sufficient:

  • holder
  • repeated credits (could use a similar sub-message to CancelCredits called BridgeCredits?)

My assumption is that we don't actually need an explicit "reason" in the bridge call, as most of the information we would want to pass in the cancel reason would be describing that it's a bridge action, and possibly what chain its coming from. But all of this info we can just get from the target field, and knowing its a Bridge() RPC call.

So for filling the "reason" in the cancel event, can we just hardcode it in the message server to set reason = "bridge" or reason = "bridge-${target}" ?

Copy link
Member

@ryanchristo ryanchristo May 23, 2022

Choose a reason for hiding this comment

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

Just to note, this was implemented as specified in the issue (or at least to our interpretation). That being said, I do agree with the changes proposed. When automatically filling the reason for MsgCancel in the message server implementation, I would be in favor of "bridge-${target}".

Copy link
Member

Choose a reason for hiding this comment

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

sorry abt the confusion!


// bridge_target is the target chain.
string bridge_target = 2;

// bridge_recipient is the recipient address.
string bridge_recipient = 3;

// bridge_contract is the contract address.
string bridge_contract = 4;
aleem1314 marked this conversation as resolved.
Show resolved Hide resolved
}

// MsgBridgeResponse is the Msg/MsgBridge response type.
message MsgBridgeResponse {}
9 changes: 6 additions & 3 deletions x/ecocredit/client/testsuite/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,19 +714,20 @@ func (s *IntegrationTestSuite) TestTxCancel() {
name: "missing args",
args: []string{},
expectErr: true,
expectedErrMsg: "Error: accepts 1 arg(s), received 0",
expectedErrMsg: "Error: accepts 2 arg(s), received 0",
},
{
name: "too many args",
args: []string{"foo", "bar"},
args: []string{"foo", "bar", "bar1"},
expectErr: true,
expectedErrMsg: "Error: accepts 1 arg(s), received 2",
expectedErrMsg: "Error: accepts 2 arg(s), received 3",
},
{
name: "missing from flag",
args: append(
[]string{
validCredits,
"reason",
},
s.commonTxFlags()...,
),
Expand All @@ -738,6 +739,7 @@ func (s *IntegrationTestSuite) TestTxCancel() {
args: append(
[]string{
validCredits,
"reason",
makeFlagFrom(val0.Address.String()),
},
s.commonTxFlags()...,
Expand All @@ -749,6 +751,7 @@ func (s *IntegrationTestSuite) TestTxCancel() {
args: append(
[]string{
validCredits,
"reason",
makeFlagFrom(val0.Address.String()),
fmt.Sprintf("--%s=%s", flags.FlagSignMode, flags.SignModeLegacyAminoJSON),
},
Expand Down
9 changes: 6 additions & 3 deletions x/ecocredit/client/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,14 +370,16 @@ Parameters:
// TxCancelCmd returns a transaction command that cancels credits.
func TxCancelCmd() *cobra.Command {
return txFlags(&cobra.Command{
Use: "cancel [credits]",
Use: "cancel [credits] [reason]",
Short: "Cancels a specified amount of credits from the account of the transaction author (--from)",
Long: `Cancels a specified amount of credits from the account of the transaction author (--from)

Parameters:
credits: comma-separated list of credits in the form [<amount> <batch-denom>]
eg: '10 C01-20200101-20210101-001, 0.1 C01-20200101-20210101-001'`,
Args: cobra.ExactArgs(1),
eg: '10 C01-20200101-20210101-001, 0.1 C01-20200101-20210101-001'
aleem1314 marked this conversation as resolved.
Show resolved Hide resolved
reason: reason is any arbitary encoded data.
aleem1314 marked this conversation as resolved.
Show resolved Hide resolved
`,
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
credits, err := parseCancelCreditsList(args[0])
if err != nil {
Expand All @@ -390,6 +392,7 @@ Parameters:
msg := core.MsgCancel{
Holder: clientCtx.GetFromAddress().String(),
Credits: credits,
Reason: args[1],
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
},
Expand Down
Loading