Skip to content

Commit

Permalink
Rename CollectionRetrievalResult field 'batch' to 'transaction_list' (M…
Browse files Browse the repository at this point in the history
…ystenLabs/narwhal#536)

* Rename field 'batch' to 'transaction_list'

* Remove concept of batches in client facing code

* update example docs
  • Loading branch information
arun-koshy authored Aug 2, 2022
1 parent 010509a commit ccfd6c2
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 211 deletions.
10 changes: 5 additions & 5 deletions narwhal/benchmark/benchmark/full_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ def run(self, debug=False):
sleep(0.5) # Removing the store may take time.

# Recompile the latest code.
cmd = CommandMaker.compile().split()
cmd = CommandMaker.compile(False)
subprocess.run(cmd, check=True, cwd=PathMaker.node_crate_path())
# Recompile the latest code.
cmd = CommandMaker.compile().split()
cmd = CommandMaker.compile(False)
subprocess.run(cmd, check=True,
cwd=PathMaker.examples_crate_path())

Expand All @@ -88,8 +88,8 @@ def run(self, debug=False):
self.node_parameters.print(PathMaker.parameters_file())

# Run the clients (they will wait for the nodes to be ready).
workers_addresses = committee.load().workers_addresses(self.faults)
rate_share = ceil(rate / committee.load().workers())
workers_addresses = committee.workers_addresses(self.faults)
rate_share = ceil(rate / committee.workers())
for i, addresses in enumerate(workers_addresses):
for (id, address) in addresses:
cmd = CommandMaker.run_client(
Expand All @@ -102,7 +102,7 @@ def run(self, debug=False):
self._background_run(cmd, log_file)

# Run the primaries (except the faulty ones).
for i, address in enumerate(committee.load().primary_addresses(self.faults)):
for i, address in enumerate(committee.primary_addresses(self.faults)):
cmd = CommandMaker.run_no_consensus_primary(
PathMaker.key_file(i),
PathMaker.committee_file(),
Expand Down
85 changes: 26 additions & 59 deletions narwhal/examples/doc/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
## Table of Contents

- [narwhal.proto](#narwhal-proto)
- [Batch](#narwhal-Batch)
- [BatchDigest](#narwhal-BatchDigest)
- [BatchMessage](#narwhal-BatchMessage)
- [BincodeEncodedPayload](#narwhal-BincodeEncodedPayload)
- [CertificateDigest](#narwhal-CertificateDigest)
- [Collection](#narwhal-Collection)
- [CollectionError](#narwhal-CollectionError)
- [CollectionRetrievalResult](#narwhal-CollectionRetrievalResult)
- [Empty](#narwhal-Empty)
Expand All @@ -28,9 +26,9 @@
- [RoundsResponse](#narwhal-RoundsResponse)
- [Transaction](#narwhal-Transaction)
- [ValidatorData](#narwhal-ValidatorData)
- [CollectionErrorType](#narwhal-CollectionErrorType)

- [CollectionError.CollectionErrorType](#narwhal-CollectionError-CollectionErrorType)

- [Configuration](#narwhal-Configuration)
- [PrimaryToPrimary](#narwhal-PrimaryToPrimary)
- [PrimaryToWorker](#narwhal-PrimaryToWorker)
Expand All @@ -39,7 +37,7 @@
- [Validator](#narwhal-Validator)
- [WorkerToPrimary](#narwhal-WorkerToPrimary)
- [WorkerToWorker](#narwhal-WorkerToWorker)

- [Scalar Value Types](#scalar-value-types)


Expand All @@ -51,24 +49,25 @@



<a name="narwhal-Batch"></a>

### Batch
<a name="narwhal-BincodeEncodedPayload"></a>

### BincodeEncodedPayload
A bincode encoded payload. This is intended to be used in the short-term
while we don&#39;t have good protobuf definitions for Narwhal types


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| transaction | [Transaction](#narwhal-Transaction) | repeated | |
| payload | [bytes](#bytes) | | |






<a name="narwhal-BatchDigest"></a>
<a name="narwhal-CertificateDigest"></a>

### BatchDigest
### CertificateDigest



Expand All @@ -81,47 +80,16 @@



<a name="narwhal-BatchMessage"></a>
<a name="narwhal-Collection"></a>

### BatchMessage
### Collection



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| id | [BatchDigest](#narwhal-BatchDigest) | | |
| transactions | [Batch](#narwhal-Batch) | | |






<a name="narwhal-BincodeEncodedPayload"></a>

### BincodeEncodedPayload
A bincode encoded payload. This is intended to be used in the short-term
while we don&#39;t have good protobuf definitions for Narwhal types


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| payload | [bytes](#bytes) | | |






<a name="narwhal-CertificateDigest"></a>

### CertificateDigest



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| digest | [bytes](#bytes) | | |
| id | [CertificateDigest](#narwhal-CertificateDigest) | | The collection&#39;s id |
| transactions | [Transaction](#narwhal-Transaction) | repeated | The transactions that are part of the collection |



Expand All @@ -136,8 +104,8 @@ while we don&#39;t have good protobuf definitions for Narwhal types

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| id | [CertificateDigest](#narwhal-CertificateDigest) | | |
| error | [CollectionErrorType](#narwhal-CollectionErrorType) | | |
| id | [CertificateDigest](#narwhal-CertificateDigest) | | The collection for which this error refers to |
| error | [CollectionError.CollectionErrorType](#narwhal-CollectionError-CollectionErrorType) | | |



Expand All @@ -152,7 +120,7 @@ while we don&#39;t have good protobuf definitions for Narwhal types

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| batch | [BatchMessage](#narwhal-BatchMessage) | | |
| collection | [Collection](#narwhal-Collection) | | |
| error | [CollectionError](#narwhal-CollectionError) | | |


Expand All @@ -178,7 +146,7 @@ Empty message for when we don&#39;t have anything to return

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| collection_ids | [CertificateDigest](#narwhal-CertificateDigest) | repeated | List of collections to be retreived. |
| collection_ids | [CertificateDigest](#narwhal-CertificateDigest) | repeated | List of collections to be retrieved. |



Expand Down Expand Up @@ -416,12 +384,12 @@ Empty message for when we don&#39;t have anything to return






<a name="narwhal-CollectionErrorType"></a>

### CollectionErrorType
<a name="narwhal-CollectionError-CollectionErrorType"></a>

### CollectionError.CollectionErrorType


| Name | Number | Description |
Expand All @@ -431,9 +399,9 @@ Empty message for when we don&#39;t have anything to return
| COLLECTION_ERROR | 2 | |









<a name="narwhal-Configuration"></a>
Expand Down Expand Up @@ -522,7 +490,7 @@ The worker-to-worker interface
| SendMessage | [BincodeEncodedPayload](#narwhal-BincodeEncodedPayload) | [Empty](#narwhal-Empty) | Sends a worker message |
| ClientBatchRequest | [BincodeEncodedPayload](#narwhal-BincodeEncodedPayload) | [BincodeEncodedPayload](#narwhal-BincodeEncodedPayload) stream | requests a number of batches that the service then streams back to the client |





Expand All @@ -545,4 +513,3 @@ The worker-to-worker interface
| <a name="bool" /> bool | | bool | boolean | boolean | bool | bool | boolean | TrueClass/FalseClass |
| <a name="string" /> string | A string must always contain UTF-8 encoded or 7-bit ASCII text. | string | String | str/unicode | string | string | string | String (UTF-8) |
| <a name="bytes" /> bytes | May contain any arbitrary sequence of bytes. | string | ByteString | str | []byte | ByteString | string | String (ASCII-8BIT) |

40 changes: 18 additions & 22 deletions narwhal/examples/protos/narwhal.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,20 @@ message CertificateDigest {
bytes digest = 1;
}

message BatchDigest {
bytes digest = 1;
}

message Batch {
repeated Transaction transaction = 1;
}

message Transaction {
bytes transaction = 1;
}

enum CollectionErrorType {
COLLECTION_NOT_FOUND = 0;
COLLECTION_TIMEOUT = 1;
COLLECTION_ERROR = 2;
}

message CollectionError {
// The collection for which this error refers to
CertificateDigest id = 1;
CollectionErrorType error = 2;
}

message BatchMessage {
BatchDigest id = 1;
Batch transactions = 2;
enum CollectionErrorType {
COLLECTION_NOT_FOUND = 0;
COLLECTION_TIMEOUT = 1;
COLLECTION_ERROR = 2;
}
CollectionErrorType error = 2;
}

message PrimaryAddresses {
Expand All @@ -56,15 +44,23 @@ message ValidatorData {
PrimaryAddresses primary_addresses = 3;
}

message Collection {
// The collection's id
CertificateDigest id = 1;

// The transactions that are part of the collection
repeated Transaction transactions = 2;
}

message CollectionRetrievalResult {
oneof retrieval_result {
BatchMessage batch = 1;
Collection collection = 1;
CollectionError error = 2;
}
}

message GetCollectionsRequest {
// List of collections to be retreived.
// List of collections to be retrieved.
repeated CertificateDigest collection_ids = 1;
}

Expand Down Expand Up @@ -192,4 +188,4 @@ service Transactions {

// Submit a Transactions
rpc SubmitTransactionStream(stream Transaction) returns (Empty) {}
}
}
31 changes: 12 additions & 19 deletions narwhal/examples/src/demo_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
use clap::{crate_name, crate_version, App, AppSettings, Arg, SubCommand};
use narwhal::{
collection_retrieval_result::RetrievalResult, proposer_client::ProposerClient,
validator_client::ValidatorClient, BatchDigest, CertificateDigest, CollectionRetrievalResult,
Empty, GetCollectionsRequest, GetCollectionsResponse, NodeReadCausalRequest,
NodeReadCausalResponse, PublicKey, ReadCausalRequest, ReadCausalResponse,
RemoveCollectionsRequest, RoundsRequest, RoundsResponse,
validator_client::ValidatorClient, CertificateDigest, CollectionRetrievalResult, Empty,
GetCollectionsRequest, GetCollectionsResponse, NodeReadCausalRequest, NodeReadCausalResponse,
PublicKey, ReadCausalRequest, ReadCausalResponse, RemoveCollectionsRequest, RoundsRequest,
RoundsResponse,
};
use std::{
fmt,
Expand Down Expand Up @@ -337,7 +337,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// TODO: This doesn't work in Docker yet, figure out why
println!("\tFound {total_num_of_transactions} transactions with a total size of {total_transactions_size} bytes\n");

println!("\tWaiting for validators to decide wheter to vote for the block...\n");
println!("\tWaiting for validators to decide whether to vote for the block...\n");
println!("\tVote completed successfully, block can be removed!\n");

println!("\n4) Remove collections that have been voted on and committed.\n");
Expand Down Expand Up @@ -365,8 +365,8 @@ fn get_total_transaction_count_and_size(result: Vec<CollectionRetrievalResult>)
let mut total_transactions_size = 0;
for r in result {
match r.retrieval_result.unwrap() {
RetrievalResult::Batch(message) => {
for t in message.transactions.unwrap().transaction {
RetrievalResult::Collection(collection) => {
for t in collection.transactions {
total_transactions_size += t.transaction.len();
total_num_of_transactions += 1;
}
Expand Down Expand Up @@ -413,20 +413,19 @@ impl std::fmt::Display for GetCollectionsResponse {

for r in self.result.clone() {
match r.retrieval_result.unwrap() {
RetrievalResult::Batch(message) => {
let batch_id = &message.id.unwrap();
//let batch_id = &message.id.unwrap();
RetrievalResult::Collection(collection) => {
let collection_id = &collection.id.unwrap();
let mut transactions_size = 0;
let mut num_of_transactions = 0;

for t in message.transactions.unwrap().transaction {
for t in collection.transactions {
transactions_size += t.transaction.len();
num_of_transactions += 1;
}

result = format!(
"{}\n\t|-Batch id {}, transactions {}, size: {} bytes",
result, batch_id, num_of_transactions, transactions_size
"{}\n\t|-Collection id {}, transactions {}, size: {} bytes",
result, collection_id, num_of_transactions, transactions_size
);
}
RetrievalResult::Error(error) => {
Expand Down Expand Up @@ -531,12 +530,6 @@ impl std::fmt::Display for CertificateDigest {
}
}

impl std::fmt::Display for BatchDigest {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{}", base64::encode(&self.digest))
}
}

fn println_and_into_inner<T>(result: Result<tonic::Response<T>, Status>) -> Option<T>
where
T: Display,
Expand Down
Loading

0 comments on commit ccfd6c2

Please sign in to comment.