Skip to content

Commit

Permalink
support submit query session transaction (WIP) (#231)
Browse files Browse the repository at this point in the history
* support query session transaction

* add ut for estimation for query session gas

* support submit query session with mock keypair

* compile fix

* Write request mutation --> payload

* load node key from tendermint config

* remove unused code from node key

* fix java sdk WriteRequest

* fix: fix Error on broadcastTxCommit when running integration test for store/mutation sdk and node test

* rust fmt

* cicd: add db3-log upload

* conditional upload db3 logs

* upload tm log

* fix node start failure

* rust fmt

* fix query session bill and account apply and add test for close session and apply query session

* rust fmt

* fix start localnet script
  • Loading branch information
jingchen2222 authored Dec 14, 2022
1 parent 9bbe8de commit 3dafe3c
Show file tree
Hide file tree
Showing 30 changed files with 696 additions and 148 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ jobs:
- name: Run rust test with coverage
run: |
cargo llvm-cov nextest --workspace --exclude merkdb --lcov --output-path lcov.info --no-fail-fast
- uses: actions/upload-artifact@v3
if: failure()
with:
name: db3-log-artifact
path: |
tools/db3.log
tools/tm.log
- name: Rust java sdk test
run: |
cd java && mvn test
Expand Down
3 changes: 2 additions & 1 deletion java/src/main/java/network/db3/sdk/mutation/MutationSDK.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public String submit(Db3Mutation.Mutation mutation) {
byte[] message = mutation.toByteArray();
Ed25519Signature signature = signer.sign(message);
Db3Mutation.WriteRequest.Builder builder = Db3Mutation.WriteRequest.newBuilder();
builder.setMutation(ByteString.copyFrom(message));
builder.setPayload(ByteString.copyFrom(message));
builder.setPayloadType(Db3Mutation.PayloadType.MutationPayload);
builder.setSignature(ByteString.copyFrom(signature.toByteArray()));
builder.setPublicKey(ByteString.copyFrom(signer.getPublicKey().toByteArray()));
Db3Mutation.WriteRequest request = builder.build();
Expand Down
1 change: 1 addition & 0 deletions src/base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ rust_secp256k1 = { version = "0.24.0", package = "secp256k1", features = ["recov
fastcrypto="0.1.3"
db3-proto={path="../proto", version="0.1.0"}
ed25519-dalek = "1.0.1"
rand = "0.8.5"
2 changes: 1 addition & 1 deletion src/base/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
mod get_address;
pub use get_address::get_address_from_pk;
mod test_base;
pub use test_base::{get_a_static_address, get_a_static_keypair};
pub use test_base::{get_a_random_nonce, get_a_static_address, get_a_static_keypair};
pub mod strings;
9 changes: 7 additions & 2 deletions src/base/src/test_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use super::get_address_from_pk;
use ed25519_dalek::{Keypair, PublicKey, SecretKey, PUBLIC_KEY_LENGTH, SECRET_KEY_LENGTH};
use ethereum_types::Address as AccountAddress;
use hex::FromHex;

use rand::{thread_rng, Rng};
// this function is used for testing
pub fn get_a_static_keypair() -> Keypair {
let secret_key: &[u8] = b"833fe62409237b9d62ec77587520911e9a759cec1d19755b7da901b96dca3d42";
Expand All @@ -30,7 +30,12 @@ pub fn get_a_static_keypair() -> Keypair {
let public: PublicKey = PublicKey::from_bytes(&pub_bytes[..PUBLIC_KEY_LENGTH]).unwrap();
Keypair { secret, public }
}

// this function is used for testing
pub fn get_a_random_nonce() -> u64 {
let mut rng = rand::thread_rng();
let nonce = rng.gen_range(0..11000);
nonce
}
pub fn get_a_static_address() -> AccountAddress {
let kp = get_a_static_keypair();
get_address_from_pk(&kp.public)
Expand Down
9 changes: 5 additions & 4 deletions src/cmd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ use db3_base::{get_address_from_pk, strings};
use db3_proto::db3_account_proto::Account;
use db3_proto::db3_base_proto::{ChainId, ChainRole, UnitType, Units};
use db3_proto::db3_mutation_proto::{KvPair, Mutation, MutationAction};
use db3_proto::db3_node_proto::{OpenSessionResponse, SessionStatus};
use db3_proto::db3_node_proto::OpenSessionResponse;
use db3_proto::db3_session_proto::SessionStatus;
use db3_sdk::mutation_sdk::MutationSDK;
use db3_sdk::store_sdk::StoreSDK;
use ed25519_dalek::Keypair;
Expand Down Expand Up @@ -137,10 +138,10 @@ async fn close_session(
.close_session(&session.as_ref().unwrap().session_token)
.await
{
Ok((sess_info_node, sess_info_client)) => {
Ok((sess_info_node, sess_info_client, hash)) => {
println!(
"Close Session Successfully!\nNode session {:?}\nClient session: {:?}",
sess_info_node, sess_info_client
"Close Session Successfully!\nNode session {:?}\nClient session: {:?}\nSubmit query session tx: {}",
sess_info_node, sess_info_client, hash
);
// set session_id to 0
*session = None;
Expand Down
8 changes: 6 additions & 2 deletions src/error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use thiserror::Error;
pub enum DB3Error {
#[error("fail to require lock from state")]
StateLockBusyError,
#[error("fail to load key pair {0}")]
LoadKeyPairError(String),
#[error("fail to sign a message with error {0}")]
SignError(String),
#[error("fail to verify the request with error {0}")]
Expand All @@ -29,8 +31,10 @@ pub enum DB3Error {
KeyCodecError(String),
#[error("fail to apply mutation with error {0}")]
ApplyMutationError(String),
#[error("fail to submit mutation with error {0}")]
#[error("fail to submit mutation session with error {0}")]
SubmitMutationError(String),
#[error("fail to submit request with error {0}")]
SubmitRequestError(String),
#[error("fail to apply bill with error {0}")]
ApplyBillError(String),
#[error("fail to query bill with error {0}")]
Expand All @@ -53,7 +57,7 @@ pub enum DB3Error {
QueryKvError(String),
#[error("fail to query, invalid session status {0}")]
QuerySessionStatusError(String),
#[error("fail to verify query session")]
#[error("fail to verify query session {0}")]
QuerySessionVerifyError(String),
}

Expand Down
3 changes: 2 additions & 1 deletion src/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ bytes = { version = "1.0", default-features = false }
tendermint-abci = "0.27.0"
tendermint-proto = "0.27.0"
tendermint-rpc = {version = "0.27.0", features=["http-client"]}
tendermint-config = "0.27.0"
tendermint = "0.27.0"
actix-web = "4.2.1"
actix-cors = "0.6"
Expand Down Expand Up @@ -49,7 +50,7 @@ http = "0.2"
shadow-rs = "0.18.0"
tower-http = { version = "0.3", features = ["cors"] }
ctrlc = { version = "3.0", features = ["termination"] }

ed25519-dalek = "1.0.1"
[build-dependencies]
shadow-rs = "0.18.0"
[dev-dependencies]
Expand Down
Loading

0 comments on commit 3dafe3c

Please sign in to comment.