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

Split MainchainService into ValidatorService and WalletService, update ValidatorService #5

Merged
merged 7 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 16 additions & 0 deletions proto/cusf/mainchain/v1/common.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* Common message types */

syntax = "proto3";
package cusf.mainchain.v1;

import "google/protobuf/wrappers.proto";

/// Consensus-encoded hex
message ConsensusHex {
google.protobuf.StringValue hex = 1;
}

/// Reverse-encoded hex
message ReverseHex {
google.protobuf.StringValue hex = 1;
}
Original file line number Diff line number Diff line change
@@ -1,41 +1,36 @@
/* CUSF mainchain node service */
/* CUSF mainchain validator service */

syntax = "proto3";
package cusf.mainchain.v1;

import "google/protobuf/wrappers.proto";

enum AddressType {
ADDRESS_TYPE_UNSPECIFIED = 0;
ADDRESS_TYPE_DEFAULT = 1;
ADDRESS_TYPE_BECH32 = 2;
ADDRESS_TYPE_LEGACY = 3;
ADDRESS_TYPE_P2SH_SEGWIT = 4;
}
import "cusf/mainchain/v1/common.proto";

message BlockHeaderInfo {
bytes block_hash = 1;
bytes prev_block_hash = 2;
ReverseHex block_hash = 1;
ReverseHex prev_block_hash = 2;
uint32 height = 3;
// Total work as a uint256, little-endian
bytes work = 4;
ConsensusHex work = 4;
}

enum Network {
NETWORK_UNSPECIFIED = 0;
NETWORK_MAINNET = 1;
NETWORK_REGTEST = 2;
NETWORK_SIGNET = 3;
NETWORK_TESTNET = 4;
NETWORK_UNKNOWN = 1;
NETWORK_MAINNET = 2;
NETWORK_REGTEST = 3;
NETWORK_SIGNET = 4;
NETWORK_TESTNET = 5;
}

message OutPoint {
bytes txid = 1;
ConsensusHex txid = 1;
uint32 vout = 2;
}

message Output {
bytes address = 2;
ConsensusHex address = 2;
uint64 value_sats = 3;
}

Expand All @@ -46,47 +41,30 @@ message Deposit {
}

enum WithdrawalBundleEventType {
WITHDRAWAL_BUNDLE_EVENT_TYPE_SUBMITTED_UNSPECIFIED = 0;
WITHDRAWAL_BUNDLE_EVENT_TYPE_FAILED = 1;
WITHDRAWAL_BUNDLE_EVENT_TYPE_SUCCEDED = 2;
WITHDRAWAL_BUNDLE_EVENT_TYPE_UNSPECIFIED = 0;
WITHDRAWAL_BUNDLE_EVENT_TYPE_SUBMITTED = 1;
WITHDRAWAL_BUNDLE_EVENT_TYPE_FAILED = 2;
WITHDRAWAL_BUNDLE_EVENT_TYPE_SUCCEDED = 3;
}

message WithdrawalBundleEvent {
bytes m6id = 1;
ConsensusHex m6id = 1;
WithdrawalBundleEventType withdrawal_bundle_event_type = 2;
}

// Specific to an individual sidechain slot
message BlockInfo {
repeated Deposit deposits = 1;
optional WithdrawalBundleEvent withdrawal_bundle_event = 2;
optional bytes bmm_commitment = 3;
}

enum AckBundlesTag {
ACK_BUNDLES_TAG_UNSPECIFIED = 0;
ACK_BUNDLES_TAG_REPEAT_PREVIOUS = 1;
ACK_BUNDLES_TAG_LEADING_BY_50 = 2;
ACK_BUNDLES_TAG_UPVOTES = 3;
repeated WithdrawalBundleEvent withdrawal_bundle_events = 2;
optional ConsensusHex bmm_commitment = 3;
}

service MainchainService {
rpc BroadcastWithdrawalBundle(BroadcastWithdrawalBundleRequest)
returns (BroadcastWithdrawalBundleResponse);
rpc CreateBmmCriticalDataTransaction(CreateBmmCriticalDataTransactionRequest)
returns (CreateBmmCriticalDataTransactionResponse);
rpc CreateDepositTransaction(CreateDepositTransactionRequest)
returns (CreateDepositTransactionResponse);
rpc CreateNewAddress(CreateNewAddressRequest)
returns (CreateNewAddressResponse);
// Regtest only
rpc GenerateBlocks(GenerateBlocksRequest)
returns (GenerateBlocksResponse);
service ValidatorService {
rpc GetBlockHeaderInfo(GetBlockHeaderInfoRequest)
returns (GetBlockHeaderInfoResponse);
rpc GetBlockInfo(GetBlockInfoRequest) returns (GetBlockInfoResponse);
rpc GetBmmHStarCommitments(GetBmmHStarCommitmentsRequest)
returns (GetBmmHStarCommitmentsResponse);
rpc GetBmmHStarCommitment(GetBmmHStarCommitmentRequest)
returns (GetBmmHStarCommitmentResponse);
rpc GetChainInfo(GetChainInfoRequest) returns (GetChainInfoResponse);
rpc GetChainTip(GetChainTipRequest) returns (GetChainTipResponse);
rpc GetCoinbasePSBT(GetCoinbasePSBTRequest) returns (GetCoinbasePSBTResponse);
Expand All @@ -100,78 +78,36 @@ service MainchainService {
returns (stream SubscribeEventsResponse);
}

message BroadcastWithdrawalBundleRequest {
google.protobuf.UInt32Value sidechain_id = 1;
google.protobuf.BytesValue transaction = 2;
}
message BroadcastWithdrawalBundleResponse {
}

message CreateBmmCriticalDataTransactionRequest {
google.protobuf.UInt32Value sidechain_id = 1;
google.protobuf.UInt64Value value_sats = 2;
google.protobuf.UInt32Value height = 3;
google.protobuf.BytesValue critical_hash = 4;
google.protobuf.BytesValue prev_bytes = 5;
}
message CreateBmmCriticalDataTransactionResponse {
bytes txid = 1;
}

message CreateDepositTransactionRequest {
uint32 sidechain_id = 1;
string address = 2;
uint64 value_sats = 3;
uint64 fee_sats = 4;
}
message CreateDepositTransactionResponse {
bytes txid = 1;
}

message CreateNewAddressRequest {
optional string label = 1;
AddressType address_type = 2;
}
message CreateNewAddressResponse {
string address = 1;
}

message GenerateBlocksRequest {
google.protobuf.UInt32Value blocks = 1;
}
message GenerateBlocksResponse {
}

message GetBlockHeaderInfoRequest {
google.protobuf.BytesValue block_hash = 1;
ReverseHex block_hash = 1;
}
message GetBlockHeaderInfoResponse {
BlockHeaderInfo header_info = 1;
}

message GetBlockInfoRequest {
google.protobuf.BytesValue block_hash = 1;
ReverseHex block_hash = 1;
google.protobuf.UInt32Value sidechain_id = 2;
}
message GetBlockInfoResponse {
BlockHeaderInfo header_info = 1;
BlockInfo block_info = 2;
}

message GetBmmHStarCommitmentsRequest {
google.protobuf.BytesValue block_hash = 1;
message GetBmmHStarCommitmentRequest {
ReverseHex block_hash = 1;
google.protobuf.UInt32Value sidechain_id = 2;
}
message GetBmmHStarCommitmentsResponse {
message GetBmmHStarCommitmentResponse {
message BlockNotFoundError {
bytes block_hash = 1;
ReverseHex block_hash = 1;
}
message Commitments {
repeated bytes commitments = 1;
message Commitment {
optional ConsensusHex commitment = 1;
}
oneof result {
BlockNotFoundError block_not_found = 1;
Commitments commitments = 2;
Commitment commitment = 2;
}
}

Expand All @@ -190,37 +126,46 @@ message GetChainTipResponse {
message GetCoinbasePSBTRequest {
message ProposeSidechain {
google.protobuf.UInt32Value sidechain_number = 1;
google.protobuf.BytesValue data = 2;
ConsensusHex data = 2;
}
message AckSidechain {
google.protobuf.UInt32Value sidechain_number = 1;
google.protobuf.BytesValue data_hash = 2;
ConsensusHex data_hash = 2;
}
message ProposeBundle {
google.protobuf.UInt32Value sidechain_number = 1;
google.protobuf.BytesValue bundle_txid = 2;
ConsensusHex bundle_txid = 2;
}
message AckBundles {
AckBundlesTag tag = 1;
repeated uint32 upvotes = 2;
message RepeatPrevious {
}
message LeadingBy50 {
}
message Upvotes {
repeated uint32 upvotes = 1;
}
oneof ack_bundles {
RepeatPrevious repeat_previous = 1;
LeadingBy50 leading_by_50 = 2;
Upvotes upvotes = 3;
}
}


repeated ProposeSidechain propose_sidechains = 1;
repeated AckSidechain ack_sidechains = 2;
repeated ProposeBundle propose_bundles = 3;
AckBundles ack_bundles = 4;
}
message GetCoinbasePSBTResponse {
bytes psbt = 1;
ConsensusHex psbt = 1;
}

message GetCtipRequest {
google.protobuf.UInt32Value sidechain_number = 1;
}
message GetCtipResponse {
message Ctip {
bytes txid = 1;
ConsensusHex txid = 1;
uint32 vout = 2;
uint64 value = 3;
uint64 sequence_number = 4;
Expand All @@ -233,8 +178,8 @@ message GetSidechainProposalsRequest {
message GetSidechainProposalsResponse {
message SidechainProposal {
uint32 sidechain_number = 1;
bytes data = 2;
bytes data_hash = 3;
google.protobuf.BytesValue data = 2;
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to decode this data into a meaningful message? I.e. version, title, description and the two hashes

https://github.com/bitcoin/bips/blob/master/bip-0300.mediawiki#m1----propose-sidechain

ConsensusHex data_hash = 3;
uint32 vote_count = 4;
uint32 proposal_height = 5;
uint32 proposal_age = 6;
Expand All @@ -247,7 +192,7 @@ message GetSidechainsRequest {
message GetSidechainsResponse {
message SidechainInfo {
uint32 sidechain_number = 1;
bytes data = 2;
google.protobuf.BytesValue data = 2;
uint32 vote_count = 3;
uint32 proposal_height = 4;
uint32 activation_height = 5;
Expand All @@ -257,8 +202,8 @@ message GetSidechainsResponse {

message GetTwoWayPegDataRequest {
google.protobuf.UInt32Value sidechain_id = 1;
optional bytes start_block_hash = 2;
google.protobuf.BytesValue end_block_hash = 3;
optional ReverseHex start_block_hash = 2;
ReverseHex end_block_hash = 3;
}
message GetTwoWayPegDataResponse {
message ResponseItem {
Expand All @@ -278,7 +223,7 @@ message SubscribeEventsResponse {
BlockInfo block_info = 2;
}
message DisconnectBlock {
bytes block_hash = 1;
ReverseHex block_hash = 1;
}
oneof event {
ConnectBlock connect_block = 1;
Expand Down
72 changes: 72 additions & 0 deletions proto/cusf/mainchain/v1/wallet.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* CUSF mainchain wallet service */

syntax = "proto3";
package cusf.mainchain.v1;

import "google/protobuf/wrappers.proto";

import "cusf/mainchain/v1/common.proto";

enum AddressType {
ADDRESS_TYPE_UNSPECIFIED = 0;
ADDRESS_TYPE_DEFAULT = 1;
ADDRESS_TYPE_BECH32 = 2;
ADDRESS_TYPE_LEGACY = 3;
ADDRESS_TYPE_P2SH_SEGWIT = 4;
}

service WalletService {
rpc BroadcastWithdrawalBundle(BroadcastWithdrawalBundleRequest)
returns (BroadcastWithdrawalBundleResponse);
rpc CreateBmmCriticalDataTransaction(CreateBmmCriticalDataTransactionRequest)
returns (CreateBmmCriticalDataTransactionResponse);
rpc CreateDepositTransaction(CreateDepositTransactionRequest)
returns (CreateDepositTransactionResponse);
rpc CreateNewAddress(CreateNewAddressRequest)
returns (CreateNewAddressResponse);
// Regtest only
rpc GenerateBlocks(GenerateBlocksRequest)
returns (GenerateBlocksResponse);
Comment on lines +28 to +29
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this can be axed. Generating blocks currently happens through the contrib/signet/miner script provided by Bitcoin Core, with minor tweaks by us. I'm currently working on a tweak here where we pass in CLI args for extra OP_RETURN messages that we want to add, which will let us do sidechain management. If we instead do generation through the wallet service, I think it'll end up being very hairy and complex

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is only for Regtest mode, so the signet script is irrelevant

Copy link
Contributor

Choose a reason for hiding this comment

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

So what I'm thinking for signet is:

  1. The validator exposes an endpoint for constructing the correct M{1-6} OP_RETURN messages
  2. The signet miner script takes in these OP_RETURN messages, adding them to the coinbase vouts

For mining on regtest, the signet miner script could be modified to remove the signet parts, but keep the rest. Sidechain management on signet needs to be implemented anyways, and we need not too-cumbersome ways of doing this on regtest as well. I.e. not re-implement the block construction logic.

The way bitcoin-cli does it with -generate does not work for us. Under the hood that defers to generatetoaddress, and there's no way of specifying coinbase outputs there.

}

message BroadcastWithdrawalBundleRequest {
google.protobuf.UInt32Value sidechain_id = 1;
google.protobuf.BytesValue transaction = 2;
}
message BroadcastWithdrawalBundleResponse {
}

message CreateBmmCriticalDataTransactionRequest {
google.protobuf.UInt32Value sidechain_id = 1;
google.protobuf.UInt64Value value_sats = 2;
google.protobuf.UInt32Value height = 3;
ConsensusHex critical_hash = 4;
ConsensusHex prev_bytes = 5;
}
message CreateBmmCriticalDataTransactionResponse {
ConsensusHex txid = 1;
}

message CreateDepositTransactionRequest {
uint32 sidechain_id = 1;
string address = 2;
uint64 value_sats = 3;
uint64 fee_sats = 4;
}
message CreateDepositTransactionResponse {
ConsensusHex txid = 1;
}

message CreateNewAddressRequest {
optional string label = 1;
AddressType address_type = 2;
}
message CreateNewAddressResponse {
string address = 1;
}

message GenerateBlocksRequest {
google.protobuf.UInt32Value blocks = 1;
}
message GenerateBlocksResponse {
}