diff --git a/protobuf/CasperMessage.proto b/protobuf/CasperMessage.proto index d117652..861deed 100644 --- a/protobuf/CasperMessage.proto +++ b/protobuf/CasperMessage.proto @@ -18,190 +18,29 @@ import "Either.proto"; option (scalapb.options) = { package_name: "coop.rchain.casper.protocol" flat_package: true + single_file: true + preamble: "sealed trait CasperMessage" }; -// --------- DeployService -------- - -// Use `DoDeploy` to queue deployments of Rholang code and then -// `createBlock` to make a new block with the results of running them -// all. -// -// To get results back, use `listenForDataAtName`. -service DeployService { - // Queue deployment of Rholang code (or fail to parse). - // Returns on success DeployServiceResponse - rpc DoDeploy(DeployData) returns (Either) {} - // Add a block including all pending deploys. - // Returns on success DeployServiceResponse - rpc createBlock(google.protobuf.Empty) returns (Either) {} - // Get details about a particular block. - // Returns on success BlockQueryResponse - rpc showBlock(BlockQuery) returns (Either) {} - // Get dag - // Returns on success VisualizeBlocksResponse - rpc visualizeDag(VisualizeDagQuery) returns (Either) {} - // Returns on success BlockInfoWithoutTuplespace - rpc showMainChain(BlocksQuery) returns (stream Either) {} - // Get a summary of blocks on the blockchain. - // Returns on success BlockInfoWithoutTuplespace - rpc showBlocks(BlocksQuery) returns (stream Either) {} - // Find data sent to a name. - // Returns on success ListeningNameDataResponse - rpc listenForDataAtName(DataAtNameQuery) returns (Either) {} - // Find processes receiving on a name. - // Returns on success ListeningNameContinuationResponse - rpc listenForContinuationAtName(ContinuationAtNameQuery) returns (Either) {} - // Find block from a deploy. - // Returns on success BlockQueryResponse - rpc findBlockWithDeploy(FindDeployInBlockQuery) returns (Either) {} - // Preview new top-level unforgeable names (for example, to compute signatures over them). - // Returns on success PrivateNamePreviewResponse - rpc previewPrivateNames(PrivateNamePreviewQuery) returns (Either) {} +message HasBlockRequest { + option (scalapb.message).extends = "CasperMessage"; + bytes hash = 1; } - -/** - * Note: deploys are uniquely keyed by `user`, `timestamp`. - * - * **TODO**: details of signatures and payment. See RHOL-781 - */ -message DeployData { - bytes deployer = 1; //public key - string term = 2; //rholang source code to deploy (will be parsed into `Par`) - int64 timestamp = 3; //millisecond timestamp - bytes sig = 4; //signature of (hash(term) + timestamp) using private key - string sigAlgorithm = 5; //name of the algorithm used to sign - int64 phloPrice = 7; //phlo price - int64 phloLimit = 8; //phlo limit for the deployment - int64 validAfterBlockNumber = 10; +message HasBlock { + option (scalapb.message).extends = "CasperMessage"; + bytes hash = 1; } message BlockRequest { - //Fields are redundant to allow for validity check. - //Such a check can definitively distinguish this - //from other message types with similar serializations. - string base16Hash = 1; - bytes hash = 2; + option (scalapb.message).extends = "CasperMessage"; + bytes hash = 1; } message ForkChoiceTipRequest { + option (scalapb.message).extends = "CasperMessage"; } -message FindDeployInBlockQuery { - bytes user = 1; - int64 timestamp = 2; -} - -message BlockQuery { - string hash = 1; -} - -message BlocksQuery { - int32 depth = 1; -} - -message DataAtNameQuery { - int32 depth = 1; - Par name = 2; -} - -message ContinuationAtNameQuery { - int32 depth = 1; - repeated Par names = 2; -} - -message DeployServiceResponse { - string message = 1; -} - -message MaybeBlockMessage { - BlockMessage block = 1; -} - -message BlockQueryResponse { - BlockInfo blockInfo = 1; -} - -message VisualizeDagQuery { - int32 depth = 1; - bool showJustificationLines = 2; -} - -message VisualizeBlocksResponse { - string content = 1; -} - -message ListeningNameDataResponse { - repeated DataWithBlockInfo blockResults = 1; - int32 length = 2; -} - -message ListeningNameContinuationResponse { - repeated ContinuationsWithBlockInfo blockResults = 1; - int32 length = 2; -} - -message DataWithBlockInfo { - repeated Par postBlockData = 1; - BlockInfoWithoutTuplespace block = 2; -} - -message ContinuationsWithBlockInfo { - repeated WaitingContinuationInfo postBlockContinuations = 1; - BlockInfoWithoutTuplespace block = 2; -} - -message WaitingContinuationInfo { - repeated BindPattern postBlockPatterns = 1; - Par postBlockContinuation = 2; -} - -message BlockInfoWithoutTuplespace { - string blockHash = 1; - string blockSize = 2; - int64 blockNumber = 3; - int64 version = 4; - int32 deployCount = 5; - string tupleSpaceHash = 6; // Same as postStateHash of BlockMessage - int64 timestamp = 7; - float faultTolerance = 8; - string mainParentHash = 9; - repeated string parentsHashList = 10; - string sender = 11; -} - -// For node clients, see BlockMessage for actual Casper protocol Block representation -message BlockInfo { - string blockHash = 1; - string blockSize = 2; - int64 blockNumber = 3; - int64 version = 4; - int32 deployCount = 5; - string tupleSpaceHash = 6; // Same as postStateHash of BlockMessage - string tupleSpaceDump = 7; - int64 timestamp = 8; - float faultTolerance = 9; - string mainParentHash = 10; - repeated string parentsHashList = 11; - string sender = 12; - string shardId = 13; - repeated string bondsValidatorList = 14; - repeated string deployCost = 15; -} - -message PrivateNamePreviewQuery { - bytes user = 1; // public key a la DeployData - int64 timestamp = 2; // millisecond timestamp - int32 nameQty = 3; // how many names to preview? (max: 1024) -} - -message PrivateNamePreviewResponse { - repeated bytes ids = 1; // a la GPrivate -} - - -// --------- End DeployService -------- - // ---------- Signing Protocol --------- message ApprovedBlockCandidate { BlockMessage block = 1; @@ -209,6 +48,7 @@ message ApprovedBlockCandidate { } message UnapprovedBlock { + option (scalapb.message).extends = "CasperMessage"; ApprovedBlockCandidate candidate = 1; int64 timestamp = 2; int64 duration = 3; @@ -221,20 +61,24 @@ message Signature { } message BlockApproval { + option (scalapb.message).extends = "CasperMessage"; ApprovedBlockCandidate candidate = 1; Signature sig = 2; } message ApprovedBlock { + option (scalapb.message).extends = "CasperMessage"; ApprovedBlockCandidate candidate = 1; repeated Signature sigs = 2; } message ApprovedBlockRequest { + option (scalapb.message).extends = "CasperMessage"; string identifier = 1; } message NoApprovedBlockAvailable { + option (scalapb.message).extends = "CasperMessage"; string identifier = 1; string nodeIdentifer = 2; } @@ -243,6 +87,7 @@ message NoApprovedBlockAvailable { // --------- Core Protocol -------- message BlockMessage { + option (scalapb.message).extends = "CasperMessage"; bytes blockHash = 1; // obtained by hashing the information in the header Header header = 2; Body body = 3; @@ -280,11 +125,28 @@ message Header { bytes extraBytes = 8; } +/** + * Note: deploys are uniquely keyed by `user`, `timestamp`. + * + * **TODO**: details of signatures and payment. See RHOL-781 + */ +message DeployData { + bytes deployer = 1; //public key + string term = 2; //rholang source code to deploy (will be parsed into `Par`) + int64 timestamp = 3; //millisecond timestamp + bytes sig = 4; //signature of (hash(term) + timestamp) using private key + string sigAlgorithm = 5; //name of the algorithm used to sign + int64 phloPrice = 7; //phlo price + int64 phloLimit = 8; //phlo limit for the deployment + int64 validAfterBlockNumber = 10; +} + message ProcessedDeploy { DeployData deploy = 1; PCost cost = 2 ; - repeated Event log = 3; //the new terms and comm. rule reductions from this deploy - bool errored = 4; //true if deploy encountered a user error + repeated Event deployLog = 3; //the new terms and comm. rule reductions from this deploy + repeated Event paymentLog = 4; //the comm. rule reductions from the payment for the deploy + bool errored = 5; //true if deploy encountered a user error } message Body { @@ -319,13 +181,15 @@ message Event { message ProduceEvent { bytes channelsHash = 1; bytes hash = 2; - int32 sequenceNumber = 3; + bool persistent = 3; + int32 sequenceNumber = 4; } message ConsumeEvent { repeated bytes channelsHashes = 1; bytes hash = 2; - int32 sequenceNumber = 3; + bool persistent = 3; + int32 sequenceNumber = 4; } message CommEvent { diff --git a/protobuf/DeployService.proto b/protobuf/DeployService.proto new file mode 100644 index 0000000..839e71d --- /dev/null +++ b/protobuf/DeployService.proto @@ -0,0 +1,195 @@ +/** + * The main API is `DeployService`. + */ +syntax = "proto3"; +package coop.rchain.casper.protocol; + +import "CasperMessage.proto"; +import "google/protobuf/empty.proto"; + +// If you are building for other languages "scalapb.proto" +// can be manually obtained here: +// https://raw.githubusercontent.com/scalapb/ScalaPB/master/protobuf/scalapb/scalapb.proto +// make a scalapb directory in this file's location and place it inside + +import "scalapb/scalapb.proto"; +import "RhoTypes.proto"; +import "Either.proto"; + +option (scalapb.options) = { + package_name: "coop.rchain.casper.protocol" + flat_package: true + single_file: true +}; + +// Use `DoDeploy` to queue deployments of Rholang code and then +// `createBlock` to make a new block with the results of running them +// all. +// +// To get results back, use `listenForDataAtName`. +service DeployService { + // Queue deployment of Rholang code (or fail to parse). + // Returns on success DeployServiceResponse + rpc DoDeploy(DeployData) returns (Either) {} + // Get details about a particular block. + // Returns on success BlockQueryResponse + rpc getBlock(BlockQuery) returns (Either) {} + // Get dag + // Returns on success VisualizeBlocksResponse + rpc visualizeDag(VisualizeDagQuery) returns (stream Either) {} + rpc machineVerifiableDag(MachineVerifyQuery) returns (Either) {} + // Returns on success LightBlockInfo + rpc showMainChain(BlocksQuery) returns (stream Either) {} + // Get a summary of blocks on the blockchain. + // Returns on success LightBlockInfo + rpc getBlocks(BlocksQuery) returns (stream Either) {} + // Find data sent to a name. + // Returns on success ListeningNameDataResponse + rpc listenForDataAtName(DataAtNameQuery) returns (Either) {} + // Find processes receiving on a name. + // Returns on success ListeningNameContinuationResponse + rpc listenForContinuationAtName(ContinuationAtNameQuery) returns (Either) {} + // Find block from a deploy. + // Returns on success BlockQueryResponse + rpc findBlockWithDeploy(FindDeployInBlockQuery) returns (Either) {} + // Find block containing a deploy. + // Returns on success LightBlockQueryResponse + rpc findDeploy(FindDeployQuery) returns (Either) {} + // Preview new top-level unforgeable names (for example, to compute signatures over them). + // Returns on success PrivateNamePreviewResponse + rpc previewPrivateNames(PrivateNamePreviewQuery) returns (Either) {} + // Get details about a particular block. + // Returns on success BlockQueryResponse + rpc lastFinalizedBlock(LastFinalizedBlockQuery) returns (Either) {} +} + +message FindDeployQuery { + bytes deployId = 1; +} + +message FindDeployInBlockQuery { + bytes user = 1; + int64 timestamp = 2; +} + +message BlockQuery { + string hash = 1; +} + +message BlocksQuery { + int32 depth = 1; +} + +message DataAtNameQuery { + int32 depth = 1; + Par name = 2; +} + +message ContinuationAtNameQuery { + int32 depth = 1; + repeated Par names = 2; +} + +message DeployServiceResponse { + string message = 1; +} + +message BlockQueryResponse { + BlockInfo blockInfo = 1; +} + +message LightBlockQueryResponse { + LightBlockInfo blockInfo = 1; +} + +message VisualizeDagQuery { + int32 depth = 1; + bool showJustificationLines = 2; +} + +message VisualizeBlocksResponse { + string content = 1; +} + +message MachineVerifyQuery { + +} + +message MachineVerifyResponse { + string content = 1; +} + +message ListeningNameDataResponse { + repeated DataWithBlockInfo blockResults = 1; + int32 length = 2; +} + +message ListeningNameContinuationResponse { + repeated ContinuationsWithBlockInfo blockResults = 1; + int32 length = 2; +} + +message PrivateNamePreviewQuery { + bytes user = 1; // public key a la DeployData + int64 timestamp = 2; // millisecond timestamp + int32 nameQty = 3; // how many names to preview? (max: 1024) +} + +message PrivateNamePreviewResponse { + repeated bytes ids = 1; // a la GPrivate +} + +message LastFinalizedBlockQuery { + +} + +message LastFinalizedBlockResponse { + BlockInfo blockInfo = 1; +} + +message LightBlockInfo { + string blockHash = 1; + string blockSize = 2; + int64 blockNumber = 3; + int64 version = 4; + int32 deployCount = 5; + string tupleSpaceHash = 6; // Same as postStateHash of BlockMessage + int64 timestamp = 7; + float faultTolerance = 8; + string mainParentHash = 9; + repeated string parentsHashList = 10; + string sender = 11; +} + +// For node clients, see BlockMessage for actual Casper protocol Block representation +message BlockInfo { + string blockHash = 1; + string blockSize = 2; + int64 blockNumber = 3; + int64 version = 4; + int32 deployCount = 5; + string tupleSpaceHash = 6; // Same as postStateHash of BlockMessage + int64 timestamp = 7; + float faultTolerance = 8; + string mainParentHash = 9; + repeated string parentsHashList = 10; + string sender = 11; + string shardId = 12; + repeated string bondsValidatorList = 13; + repeated string deployCost = 14; +} + +message DataWithBlockInfo { + repeated Par postBlockData = 1; + LightBlockInfo block = 2; +} + +message ContinuationsWithBlockInfo { + repeated WaitingContinuationInfo postBlockContinuations = 1; + LightBlockInfo block = 2; +} + +message WaitingContinuationInfo { + repeated BindPattern postBlockPatterns = 1; + Par postBlockContinuation = 2; +} diff --git a/protobuf/ProposeService.proto b/protobuf/ProposeService.proto new file mode 100644 index 0000000..66cadac --- /dev/null +++ b/protobuf/ProposeService.proto @@ -0,0 +1,21 @@ +syntax = "proto3"; +package coop.rchain.casper.protocol; + +import "CasperMessage.proto"; +import "google/protobuf/empty.proto"; +import "Either.proto"; +import "scalapb/scalapb.proto"; + +option (scalapb.options) = { + package_name: "coop.rchain.casper.protocol" + flat_package: true + single_file: true +}; + +service ProposeService { + rpc propose(PrintUnmatchedSendsQuery) returns (Either) {} +} + +message PrintUnmatchedSendsQuery { + bool printUnmatchedSends = 1; +} diff --git a/protobuf/RhoTypes.proto b/protobuf/RhoTypes.proto index ee5bf32..debb075 100644 --- a/protobuf/RhoTypes.proto +++ b/protobuf/RhoTypes.proto @@ -30,7 +30,7 @@ message Par { repeated New news = 4; repeated Expr exprs = 5; repeated Match matches = 6; - repeated GPrivate ids = 7; // unforgeable names + repeated GUnforgeable unforgeables = 7; // unforgeable names repeated Bundle bundles = 11; repeated Connective connectives = 8; bytes locallyFree = 9 [(scalapb.field).type = "coop.rchain.models.AlwaysEqual[scala.collection.immutable.BitSet]"]; @@ -134,7 +134,8 @@ message Receive { repeated ReceiveBind binds = 1; Par body = 2 [(scalapb.field).no_box = true]; bool persistent = 3; - int32 bindCount = 4; + bool peek = 4; + int32 bindCount = 5; bytes locallyFree = 6 [(scalapb.field).type = "coop.rchain.models.AlwaysEqual[scala.collection.immutable.BitSet]"]; bool connective_used = 7; } @@ -149,7 +150,9 @@ message New { Par p = 2 [(scalapb.field).no_box = true]; // For normalization, uri-referenced variables come at the end, and in lexicographical order. repeated string uri = 3; - bytes locallyFree = 4 [(scalapb.field).type = "coop.rchain.models.AlwaysEqual[scala.collection.immutable.BitSet]"]; + DeployId deployId = 4; + DeployerId deployerId = 5; + bytes locallyFree = 6 [(scalapb.field).type = "coop.rchain.models.AlwaysEqual[scala.collection.immutable.BitSet]"]; } message MatchCase { @@ -201,6 +204,8 @@ message Expr { EPercentPercent e_percent_percent_body = 28; // string interpolation EPlusPlus e_plus_plus_body = 29; // concatenation EMinusMinus e_minus_minus_body = 30; // set difference + + EMod e_mod_body = 31; } } @@ -273,6 +278,11 @@ message EDiv { Par p2 = 2 [(scalapb.field).no_box = true]; } +message EMod { + Par p1 = 1 [(scalapb.field).no_box = true]; + Par p2 = 2 [(scalapb.field).no_box = true]; +} + message EPlus { Par p1 = 1 [(scalapb.field).no_box = true]; Par p2 = 2 [(scalapb.field).no_box = true]; @@ -373,9 +383,32 @@ message ConnectiveBody { repeated Par ps = 1; } +message DeployId { + bytes sig = 1; +} + +message DeployerId { + bytes publicKey = 1; +} + // Unforgeable names resulting from `new x { ... }` // These should only occur as the program is being evaluated. There is no way in // the grammar to construct them. +message GUnforgeable { + oneof unf_instance { + GPrivate g_private_body = 1; + GDeployId g_deploy_id_body = 2; + GDeployerId g_deployer_id_body = 3; + } +} message GPrivate { bytes id = 1; } + +message GDeployId { + bytes sig = 1; +} + +message GDeployerId { + bytes publicKey = 1; +}