Skip to content

Commit

Permalink
feat(weaver/common): add data view protocol buffer spec & RFCs for Besu
Browse files Browse the repository at this point in the history
Signed-off-by: VattiPraveen <[email protected]>
  • Loading branch information
VattiPraveen authored and petermetz committed Aug 2, 2023
1 parent dc85c27 commit 97f17e0
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 8 deletions.
41 changes: 41 additions & 0 deletions weaver/common/protos/besu/view_data.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
syntax = "proto3";

package besu;

option java_package = "org.hyperledger.cacti.weaver.protos.besu";
option go_package = "github.com/hyperledger/cacti/weaver/common/protos-go/v2/besu";


// link below will take you to besu view rfc
// https://github.com/hyperledger/cacti/blob/main/weaver/rfcs/formats/views/besu.md
//
// take a view at BlockHeader in Besu
// https://github.com/hyperledger/besu/blob/21.7.0/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/BlockHeader.java#L199

message BlockHeader {
// Fields representing the header of a block object
string parentHash = 1;
string sha3Uncles = 2;
string miner = 3;
string stateRoot = 4;
string transactionsRoot = 5;
string receiptsRoot = 6;
string logsBloom = 7;
string difficulty = 8;
string number = 9;
string gasLimit = 10;
string gasUsed = 11;
string timestamp = 12;
string extraData = 13;
string mixHash = 14;
string nonce = 15;
}

message BesuView {
bytes interop_payload = 1;
BlockHeader block_header = 2;
bytes merkle_proof = 3;
uint32 receipt_index = 4;
uint32 log_index = 5;
repeated bytes validator_signatures = 6;
}
48 changes: 42 additions & 6 deletions weaver/rfcs/formats/views/besu.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,63 @@ This document specifies the design of view address for remote query to Besu netw
## Addressing a Besu View

```
operator = ledger-id , ":" , contract-name/address , ":" , func-name-with-signature , [ ":" , { argument } ] ;
operator = network-id , ":" , contract-address , ":" , func-name-with-signature , [ ":" , { argument } ] ;
```

`ledger-id` is empty in case of Besu.

Example:

- ledger-id: _ (indicating empty)
- Contract Name: SimpleState
- Network-id: 123
- contract-address: 0x5FbDB2315678afecb367f032d93F642f64180aa3
- Function Name: get(string)
- Arguments: key

```
operator = _:SimpleState:get(string):key
operator = 123:0x5FbDB2315678afecb367f032d93F642f64180aa3:get(string):key
```

## View Data Definition
The view from a Besu network ledger is specified below. It consists of endorsed (i.e., signed) response to state requests made

1. Interop payload in bytes (_check_ if the requestor can directly obtain this from the output merkle-patricia-trie proof verification)
2. Header fields of block object (this also contains `receiptsRoot`).
3. [Merkle-Patricia Proof](https://ethereum.org/en/developers/docs/data-structures-and-encoding/patricia-merkle-trie/)
4. Index of receipt object of interest -> txRIndex.
5. LogIndex
6. Signatures of validators from extraData (we can obtain a validator's public key from its signature using `recover`)

Take a view at [Besu Block Header Fields](https://github.com/hyperledger/besu/blob/21.7.0/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/BlockHeader.java#L199)

```protobuf
syntax = "proto3";
message BlockHeader {
// Fields representing the header of a block object
string parentHash = 1;
string sha3Uncles = 2;
string miner = 3;
string stateRoot = 4;
string transactionsRoot = 5;
string receiptsRoot = 6;
string logsBloom = 7;
string difficulty = 8;
string number = 9;
string gasLimit = 10;
string gasUsed = 11;
string timestamp = 12;
string extraData = 13;
string mixHash = 14;
string nonce = 15;
// ...
}
message BesuView {
bytes interop_payload = 1;
BlockHeader block_header = 2;
bytes merkle_proof = 3;
uint32 receipt_index = 4;
uint32 log_index = 5;
repeated bytes validator_signatures = 6;
}
```

You can find the besu view_data.proto file [here](https://github.com/hyperledger/cacti/blob/main/weaver/common/protos/besu/view_data.proto).
4 changes: 2 additions & 2 deletions weaver/rfcs/protocols/data-sharing/besu.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ At the source network:
2. Checks that the certificate of the requester is valid according to the network's Membership.
3. Checks the access control policy for the requester and view address is met.
4. Performs a contract to contract call to the application contract, according to the view address (either verify the encoded value passed from driver, or generate the encoded value from the view address here).
5. Packages the response in InteropPayload and emit it as event `Weaver_Data_Sharing`. Make sure there is only one event defined with the name `Weaver_Data_Sharing` in Besu interop contract.
5. Packages the response in InteropPayload and emit it as event `Cacti_Data_Sharing`. Make sure there is only one event defined with the name `Cacti_Data_Sharing` in Besu interop contract.
4. Source Besu Driver:
1. Get transaction Hash (txHash) and block hash from response of interop contract call.
2. Get transactionReceipt object from txHash (`web3.eth.getTransactionReceipt`) -> txRcpt.
3. Get Interop Payload:
1. Get logs of response object, and get the `logIndex` (or `id`) of the log whose address is interop contract and the event name is `Weaver_Data_Sharing`.
1. Get logs of response object, and get the `logIndex` (or `id`) of the log whose address is interop contract and the event name is `Cacti_Data_Sharing`.
2. Parse the txRcpt object to obtain the logs[logIndex] (check if `id` matches) and then get the payload by `logs[logIndex].data`, which needs to be abi decoded. (Or parse the response object to obtain `logs[logIndex].args.interop_payload`)
4. Generate Proof:
1. Get Block Object from `blockHash`.
Expand Down

0 comments on commit 97f17e0

Please sign in to comment.