Skip to content

Commit

Permalink
feat(vn): add get_sidechain_block p2p rpc method
Browse files Browse the repository at this point in the history
  • Loading branch information
sdbondi committed Feb 7, 2022
1 parent bbd0e1e commit 5547ebc
Show file tree
Hide file tree
Showing 52 changed files with 1,071 additions and 391 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,7 @@ node_modules

# ignore output files from windows ISS
buildtools/Output/
/applications/tari_collectibles/src-tauri/data
/applications/tari_collectibles/src-tauri/data

# Asset files
assets/
2 changes: 2 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion applications/tari_app_grpc/proto/validator_node.proto
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,4 @@ message InvokeMethodRequest{
message InvokeMethodResponse {
string status = 1;
bytes result = 2;
}
}
1 change: 1 addition & 0 deletions applications/tari_validator_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ tari_storage = { path = "../../infrastructure/storage" }
tari_core = {path = "../../base_layer/core"}
tari_dan_core = {path = "../../dan_layer/core"}
tari_dan_storage_sqlite = {path = "../../dan_layer/storage_sqlite"}
tari_dan_common_types = {path = "../../dan_layer/common_types"}
tari_common_types = {path = "../../base_layer/common_types"}

anyhow = "1.0.53"
Expand Down
3 changes: 2 additions & 1 deletion applications/tari_validator_node/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

fn main() -> Result<(), Box<dyn std::error::Error>> {
tari_common::build::ProtobufCompiler::new()
.proto_paths(&["proto/p2p"])
.proto_paths(&["proto/dan"])
.include_paths(&["proto/dan"])
.emit_rerun_if_changed_directives()
.compile()
.unwrap();
Expand Down
27 changes: 27 additions & 0 deletions applications/tari_validator_node/proto/dan/common.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
syntax = "proto3";

package tari.dan.common;

message SideChainBlock {
Node node = 1;
InstructionSet instructions = 2;
}

message Node {
bytes hash = 1;
bytes parent = 2;
uint32 height = 3;
bool is_committed = 4;
}

message Instruction {
uint32 template_id = 1;
string method = 2;
bytes args = 3;
// bytes token_id = 5;
// bytes signature = 6;
}

message InstructionSet{
repeated Instruction instructions = 1;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
syntax = "proto3";

package tari.p2p.dan;
package tari.dan.consensus;

import "common.proto";

enum HotStuffMessageType {
HOT_STUFF_MESSAGE_TYPE_UNKNOWN = 0;
Expand Down Expand Up @@ -41,22 +43,10 @@ message Signature{
}

message TariDanPayload {
InstructionSet instruction_set = 1;
tari.dan.common.InstructionSet instruction_set = 1;
CheckpointData checkpoint = 2;
}

message CheckpointData {
// todo: fill this in
}

message InstructionSet{
repeated Instruction instructions = 1;
}
message Instruction {
bytes asset_public_key = 1;
uint32 template_id = 2;
string method = 3;
bytes args = 4;
// bytes token_id = 5;
// bytes signature = 6;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
syntax = "proto3";

package tari.p2p.validator_node;
package tari.dan.validator_node;

import "common.proto";

service ValidatorNode {
rpc GetTokenData(GetTokenDataRequest) returns (GetTokenDataResponse);
Expand Down Expand Up @@ -64,4 +66,15 @@ message InvokeMethodRequest{
message InvokeMethodResponse {
bytes result = 1;
Status status = 2;
}
}

message GetBlocksRequest {
bytes asset_public_key = 1;
bytes start_hash = 2;
bytes end_hash = 3;
}


message GetBlocksResponse {
tari.dan.common.SideChainBlock block = 1;
}
25 changes: 11 additions & 14 deletions applications/tari_validator_node/src/dan_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,27 +95,24 @@ impl DanNode {

let mut tasks = vec![];
for asset in asset_definitions {
let node_identitiy = node_identity.as_ref().clone();
let node_identity = node_identity.as_ref().clone();
let mempool = mempool_service.clone();
let handles = handles.clone();
let subscription_factory = subscription_factory.clone();
let shutdown = shutdown.clone();
let dan_config = dan_config.clone();
let db_factory = db_factory.clone();

tasks.push(task::spawn(async move {
DanNode::start_asset_worker(
asset,
node_identitiy,
mempool,
handles,
subscription_factory,
shutdown,
dan_config,
db_factory,
)
.await
}));
tasks.push(task::spawn(DanNode::start_asset_worker(
asset,
node_identity,
mempool,
handles,
subscription_factory,
shutdown,
dan_config,
db_factory,
)));
}

if tasks.is_empty() {
Expand Down
2 changes: 1 addition & 1 deletion applications/tari_validator_node/src/grpc/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl From<SidechainMetadata> for St {
Self(tari_rpc::SidechainMetadata {
asset_public_key: source.asset_public_key().as_bytes().to_vec(),
committed_height: source.committed_height().into(),
committed_hash: source.committed_hash().clone().into(),
committed_hash: source.committed_hash().as_bytes().to_vec(),
})
}
}
2 changes: 1 addition & 1 deletion applications/tari_validator_node/src/grpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
pub(crate) mod conversions;
mod conversions;
pub mod services;
pub(crate) mod validator_node_grpc_server;
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
use std::convert::TryInto;

use tari_app_grpc::tari_rpc as rpc;
use tari_common_types::types::PublicKey;
use tari_comms::NodeIdentity;
use tari_crypto::tari_utilities::ByteArray;
use tari_dan_core::{
models::TemplateId,
services::{AssetProcessor, AssetProxy, ServiceSpecification},
storage::DbFactory,
};
Expand Down Expand Up @@ -90,7 +91,10 @@ impl<TServiceSpecification: ServiceSpecification + 'static> rpc::validator_node_
.asset_proxy
.invoke_method(
&asset_public_key,
request.template_id.into(),
request
.template_id
.try_into()
.map_err(|_| Status::invalid_argument("invalid template_id"))?,
request.method.clone(),
request.args.clone(),
)
Expand Down Expand Up @@ -130,6 +134,10 @@ impl<TServiceSpecification: ServiceSpecification + 'static> rpc::validator_node_
let request = request.into_inner();
let asset_public_key = PublicKey::from_bytes(&request.asset_public_key)
.map_err(|err| Status::invalid_argument(format!("Asset public key was not a valid public key:{}", err)))?;
let template_id = request
.template_id
.try_into()
.map_err(|_| Status::invalid_argument("Invalid template_id"))?;
if let Some(state) = self
.db_factory
.get_state_db(&asset_public_key)
Expand All @@ -138,12 +146,7 @@ impl<TServiceSpecification: ServiceSpecification + 'static> rpc::validator_node_
let mut unit_of_work = state.new_unit_of_work();
let response_bytes = self
.asset_processor
.invoke_read_method(
TemplateId::from(request.template_id),
request.method,
&request.args,
&mut unit_of_work,
)
.invoke_read_method(template_id, request.method, &request.args, &mut unit_of_work)
.map_err(|e| Status::internal(format!("Could not invoke read method: {}", e)))?;
Ok(Response::new(rpc::InvokeReadMethodResponse {
result: response_bytes.unwrap_or_default(),
Expand All @@ -157,12 +160,7 @@ impl<TServiceSpecification: ServiceSpecification + 'static> rpc::validator_node_
// Forward to proxy
let response_bytes = self
.asset_proxy
.invoke_read_method(
&asset_public_key,
TemplateId::from(request.template_id),
request.method,
request.args,
)
.invoke_read_method(&asset_public_key, template_id, request.method, request.args)
.await
.map_err(|err| Status::internal(format!("Error calling proxied method:{}", err)))?;
// TODO: Populate authority
Expand Down
Loading

0 comments on commit 5547ebc

Please sign in to comment.