Skip to content

Commit

Permalink
ci
Browse files Browse the repository at this point in the history
  • Loading branch information
dvush committed May 28, 2020
1 parent 746a767 commit ca4485d
Show file tree
Hide file tree
Showing 24 changed files with 171 additions and 136 deletions.
5 changes: 4 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
*
!target/x86_64-unknown-linux-musl/release
!target/x86_64-unknown-linux-musl/release/server
!target/x86_64-unknown-linux-musl/release/server_supervisor
!target/x86_64-unknown-linux-musl/release/plonk_step_by_step_prover
!target/x86_64-unknown-linux-musl/release/dev-ticker-server
!docker/prover/prover-entry.sh
!docker/keybase-secrets/entrypoint.sh
!keys/packed
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,8 @@ jobs:
image: postgres:10.4
ports:
- 5432:5432
-
dev-ticker:
image: matterlabs/dev-ticker:latest
ports:
- 9876:9876
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ sandbox:

# See more more at https://github.com/emk/rust-musl-builder#caching-builds
build-target: build-contracts
$(rust-musl-builder) sudo chown -R rust:rust /home/rust/.cargo/git /home/rust/.cargo/registry
$(rust-musl-builder) sudo chown -R rust:rust /home/rust/src /home/rust/.cargo/git /home/rust/.cargo/registry
$(rust-musl-builder) cargo build --release

clean-target:
Expand Down Expand Up @@ -267,7 +267,7 @@ nodes:
# Dev environment

dev-up:
@docker-compose up -d postgres geth
@docker-compose up -d postgres geth dev-ticker
@docker-compose up -d tesseracts

dev-down:
Expand All @@ -287,7 +287,7 @@ dev-push-geth:
@docker push "${GETH_DOCKER_IMAGE}"

image-dev-ticker: build-target
@docker build -t "${DEV_TICKER_DOCKER_IMAGE}" ./docker/dev-ticker
@docker build -t "${DEV_TICKER_DOCKER_IMAGE}" -f ./docker/dev-ticker/Dockerfile .

push-image-dev-ticker: image-dev-ticker
@docker push "${DEV_TICKER_DOCKER_IMAGE}"
Expand Down
2 changes: 1 addition & 1 deletion core/circuit/src/witness/full_exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl Witness for FullExitWitness<Bn256> {
full_exit_amount: full_exit
.withdraw_amount
.clone()
.map(|amount| Fr::from_str(&amount.to_string()).unwrap())
.map(|amount| Fr::from_str(&amount.0.to_string()).unwrap())
.unwrap_or_else(Fr::zero),
};

Expand Down
4 changes: 2 additions & 2 deletions core/circuit/src/witness/tests/full_exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn test_full_exit_success() {
eth_address: account.account.address,
token: 0,
},
withdraw_amount: Some(BigUint::from(10u32)),
withdraw_amount: Some(BigUint::from(10u32).into()),
};
let success = true;

Expand Down Expand Up @@ -93,7 +93,7 @@ fn test_incorrect_full_exit_withdraw_amount() {
eth_address: account.account.address,
token: 0,
},
withdraw_amount: Some(withdraw_amount.into()),
withdraw_amount: Some(BigUint::from(withdraw_amount).into()),
};

incorrect_op_test_scenario::<FullExitWitness<Bn256>, _>(
Expand Down
2 changes: 1 addition & 1 deletion core/circuit/src/witness/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ fn apply_many_ops() -> FranklinCircuit<'static, Bn256> {
eth_address: account.account.address,
token: 0,
},
withdraw_amount: Some(BigUint::from(900u32)),
withdraw_amount: Some(BigUint::from(900u32).into()),
};
let full_exit_success = true;

Expand Down
3 changes: 2 additions & 1 deletion core/data_restore/src/rollup_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ mod test {
Close, CloseOp, Deposit, DepositOp, FranklinOp, FullExit, FullExitOp, PubKeyHash, Transfer,
TransferOp, TransferToNewOp, Withdraw, WithdrawOp,
};
use num::BigUint;

#[test]
fn test_deposit() {
Expand Down Expand Up @@ -161,7 +162,7 @@ mod test {
};
let op1 = FranklinOp::FullExit(Box::new(FullExitOp {
priority_op,
withdraw_amount: Some(444u32.into()),
withdraw_amount: Some(BigUint::from(444u32).into()),
}));
let pub_data1 = op1.public_data();
let op2 = RollupOpsBlock::get_rollup_ops_from_data(&pub_data1)
Expand Down
18 changes: 9 additions & 9 deletions core/models/src/node/account.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::params;
use crate::primitives::GetBits;
use crate::primitives::{BigUintSerdeWrapper, GetBits};

use std::collections::HashMap;
use std::convert::TryInto;
Expand Down Expand Up @@ -96,7 +96,7 @@ impl<'de> Deserialize<'de> for PubKeyHash {
pub struct Account {
pub pub_key_hash: PubKeyHash,
pub address: Address,
balances: HashMap<TokenId, BigUint>,
balances: HashMap<TokenId, BigUintSerdeWrapper>,
pub nonce: Nonce,
}

Expand Down Expand Up @@ -142,7 +142,7 @@ impl From<Account> for CircuitAccount<super::Engine> {
(
*id,
Balance {
value: Fr::from_str(&b.to_string()).unwrap(),
value: Fr::from_str(&b.0.to_string()).unwrap(),
},
)
})
Expand Down Expand Up @@ -236,22 +236,22 @@ impl Account {
}

pub fn get_balance(&self, token: TokenId) -> BigUint {
self.balances.get(&token).cloned().unwrap_or_default()
self.balances.get(&token).cloned().unwrap_or_default().0
}

pub fn set_balance(&mut self, token: TokenId, amount: BigUint) {
self.balances.insert(token, amount);
self.balances.insert(token, amount.into());
}

pub fn add_balance(&mut self, token: TokenId, amount: &BigUint) {
let mut balance = self.balances.remove(&token).unwrap_or_default();
balance += amount;
balance.0 += amount;
self.balances.insert(token, balance);
}

pub fn sub_balance(&mut self, token: TokenId, amount: &BigUint) {
let mut balance = self.balances.remove(&token).unwrap_or_default();
balance -= amount;
balance.0 -= amount;
self.balances.insert(token, balance);
}

Expand Down Expand Up @@ -307,9 +307,9 @@ impl Account {
}
}

pub fn get_nonzero_balances(&self) -> HashMap<TokenId, BigUint> {
pub fn get_nonzero_balances(&self) -> HashMap<TokenId, BigUintSerdeWrapper> {
let mut balances = self.balances.clone();
balances.retain(|_, v| v != &BigUint::zero());
balances.retain(|_, v| v.0 != BigUint::zero());
balances
}
}
Expand Down
11 changes: 7 additions & 4 deletions core/models/src/node/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use crate::params::{
BALANCE_BIT_WIDTH, ETH_ADDRESS_BIT_WIDTH, FEE_EXPONENT_BIT_WIDTH, FEE_MANTISSA_BIT_WIDTH,
FR_ADDRESS_LEN, NEW_PUBKEY_HASH_WIDTH, NONCE_BIT_WIDTH, TOKEN_BIT_WIDTH,
};
use crate::primitives::{bytes_slice_to_uint128, bytes_slice_to_uint16, bytes_slice_to_uint32};
use crate::primitives::{
bytes_slice_to_uint128, bytes_slice_to_uint16, bytes_slice_to_uint32, BigUintSerdeWrapper,
};
use failure::{ensure, format_err};
use num::{BigUint, FromPrimitive, ToPrimitive};
use web3::types::Address;
Expand Down Expand Up @@ -443,7 +445,7 @@ impl ChangePubKeyOp {
pub struct FullExitOp {
pub priority_op: FullExit,
/// None if withdraw was unsuccessful
pub withdraw_amount: Option<BigUint>,
pub withdraw_amount: Option<BigUintSerdeWrapper>,
}

impl FullExitOp {
Expand All @@ -462,6 +464,7 @@ impl FullExitOp {
.withdraw_amount
.clone()
.unwrap_or_default()
.0
.to_u128()
.unwrap()
.to_be_bytes(),
Expand All @@ -479,7 +482,7 @@ impl FullExitOp {
&self
.withdraw_amount
.clone()
.map(|a| a.to_u128().unwrap())
.map(|a| a.0.to_u128().unwrap())
.unwrap_or(0)
.to_be_bytes(),
);
Expand Down Expand Up @@ -514,7 +517,7 @@ impl FullExitOp {
eth_address,
token,
},
withdraw_amount: Some(amount),
withdraw_amount: Some(amount.into()),
})
}
}
Expand Down
3 changes: 2 additions & 1 deletion core/models/src/node/priority_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use super::TokenId;
use crate::params::{
ACCOUNT_ID_BIT_WIDTH, BALANCE_BIT_WIDTH, ETH_ADDRESS_BIT_WIDTH, FR_ADDRESS_LEN, TOKEN_BIT_WIDTH,
};
use crate::primitives::bytes_slice_to_uint32;
use crate::primitives::{bytes_slice_to_uint32, BigUintSerdeAsRadix10Str};
use ethabi::{decode, ParamType};
use failure::{bail, ensure, format_err};
use num::BigUint;
Expand All @@ -16,6 +16,7 @@ use super::operations::{DepositOp, FullExitOp};
pub struct Deposit {
pub from: Address,
pub token: TokenId,
#[serde(with = "BigUintSerdeAsRadix10Str")]
pub amount: BigUint,
pub to: Address,
}
Expand Down
6 changes: 5 additions & 1 deletion core/models/src/node/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::franklin_crypto::rescue::RescueEngine;
use crate::misc::utils::format_ether;
use crate::node::operations::ChangePubKeyOp;
use crate::params::{JUBJUB_PARAMS, RESCUE_PARAMS};
use crate::primitives::{pedersen_hash_tx_msg, rescue_hash_tx_msg};
use crate::primitives::{pedersen_hash_tx_msg, rescue_hash_tx_msg, BigUintSerdeAsRadix10Str};
use failure::{bail, ensure, format_err};
use parity_crypto::publickey::{
public_to_address, recover, sign, KeyPair, Signature as ETHSignature,
Expand Down Expand Up @@ -108,7 +108,9 @@ pub struct Transfer {
pub from: Address,
pub to: Address,
pub token: TokenId,
#[serde(with = "BigUintSerdeAsRadix10Str")]
pub amount: BigUint,
#[serde(with = "BigUintSerdeAsRadix10Str")]
pub fee: BigUint,
pub nonce: Nonce,
pub signature: TxSignature,
Expand Down Expand Up @@ -227,7 +229,9 @@ pub struct Withdraw {
pub from: Address,
pub to: Address,
pub token: TokenId,
#[serde(with = "BigUintSerdeAsRadix10Str")]
pub amount: BigUint,
#[serde(with = "BigUintSerdeAsRadix10Str")]
pub fee: BigUint,
pub nonce: Nonce,
pub signature: TxSignature,
Expand Down
24 changes: 15 additions & 9 deletions core/models/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,20 +511,18 @@ impl UnsignedRatioSerializeAsDecimal {

/// Used to serialize BigUint as radix 10 string.
#[derive(Clone, Debug)]
pub struct BigUintSerdeWrapper(pub BigUint);
pub struct BigUintSerdeAsRadix10Str;

impl Serialize for BigUintSerdeWrapper {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
impl BigUintSerdeAsRadix10Str {
pub fn serialize<S>(val: &BigUint, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let big_dec = BigDecimal::from(self.0.to_bigint().unwrap());
let big_dec = BigDecimal::from(val.to_bigint().unwrap());
BigDecimal::serialize(&big_dec, serializer)
}
}

impl<'de> Deserialize<'de> for BigUintSerdeWrapper {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
pub fn deserialize<'de, D>(deserializer: D) -> Result<BigUint, D::Error>
where
D: Deserializer<'de>,
{
Expand All @@ -535,12 +533,20 @@ impl<'de> Deserialize<'de> for BigUintSerdeWrapper {
.ok_or_else(|| Error::custom("Expected integer value"))?;
big_int
.to_biguint()
.map(BigUintSerdeWrapper)
.ok_or_else(|| Error::custom("Expected positive value"))
})
}
}

#[derive(Clone, Debug, Serialize, Deserialize, Default)]
pub struct BigUintSerdeWrapper(#[serde(with = "BigUintSerdeAsRadix10Str")] pub BigUint);

impl From<BigUint> for BigUintSerdeWrapper {
fn from(uint: BigUint) -> BigUintSerdeWrapper {
BigUintSerdeWrapper(uint)
}
}

pub fn ratio_to_big_decimal(num: &Ratio<BigUint>, precision: usize) -> BigDecimal {
let bigint = round_precision_raw_no_div(num, precision)
.to_bigint()
Expand All @@ -550,7 +556,7 @@ pub fn ratio_to_big_decimal(num: &Ratio<BigUint>, precision: usize) -> BigDecima

pub fn big_decimal_to_ratio(num: &BigDecimal) -> Result<Ratio<BigUint>, failure::Error> {
let (big_int, exp) = num.as_bigint_and_exponent();
failure::ensure!(big_int.is_positive(), "BigDecimal should be unsigned");
failure::ensure!(!big_int.is_negative(), "BigDecimal should be unsigned");
let big_uint = big_int.to_biguint().unwrap();
let ten_pow = BigUint::from(10 as u32).pow(exp as u128);
Ok(Ratio::new(big_uint, ten_pow))
Expand Down
6 changes: 4 additions & 2 deletions core/plasma/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use models::node::{
};
use models::node::{Close, Deposit, FranklinTx, FullExit, Transfer, Withdraw};
use models::params;
use models::primitives::BigUintSerdeWrapper;
use num::BigUint;
use std::collections::HashMap;

Expand Down Expand Up @@ -152,7 +153,8 @@ impl PlasmaState {
let account_balance = self
.get_account(priority_op.account_id)
.filter(|account| account.address == priority_op.eth_address)
.map(|acccount| acccount.get_balance(priority_op.token));
.map(|acccount| acccount.get_balance(priority_op.token))
.map(BigUintSerdeWrapper);

trace!("Balance: {:?}", account_balance);
let op = FullExitOp {
Expand Down Expand Up @@ -185,7 +187,7 @@ impl PlasmaState {
let old_balance = account.get_balance(op.priority_op.token);
let old_nonce = account.nonce;

account.sub_balance(op.priority_op.token, &amount);
account.sub_balance(op.priority_op.token, &amount.0);

let new_balance = account.get_balance(op.priority_op.token);
assert_eq!(
Expand Down
2 changes: 1 addition & 1 deletion core/server/src/api_server/rest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ fn priority_op_to_tx_history(
let tx_json = serde_json::json!({
"account_id": account_id,
"priority_op": {
"amount": deposit.amount,
"amount": deposit.amount.to_string(),
"from": deposit.from,
"to": deposit.to,
"token": token_symbol
Expand Down
Loading

0 comments on commit ca4485d

Please sign in to comment.