Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Ever-SDK Batching API #617

Open
wants to merge 14 commits into
base: dev
Choose a base branch
from
25 changes: 11 additions & 14 deletions tests/09_1-push_many_files_no_ipfs.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ set -o pipefail
. ./util.sh
set -x

FILES_CNT=500
BATCH_SIZE=200

# Test 19_1 pushes many files not to ipfs
# It checks that contracts correctly work with big amount of files, especially that they don't exceed their balances
# while processing big amount of diffs (that's why it is important to have files not in ipfs) and correctly ask for
Expand All @@ -12,7 +15,7 @@ set -x
# 2. Create dev branch and push a big amount of files to one commit
# 3. Clone the repo and check dev branch to have an appropriate number of files

REPO_NAME="repo19_$(date +%s)"
REPO_NAME="repo09_1_$(date +%s)"

[ -d $REPO_NAME ] && rm -rf $REPO_NAME
[ -d $REPO_NAME"-clone" ] && rm -rf $REPO_NAME"-clone"
Expand All @@ -33,22 +36,16 @@ git config user.email "[email protected]"
git config user.name "My name"
git branch -m main

echo 1 > 1.txt
git add 1.txt
git commit -m init
git push -u origin main

git checkout -b dev
echo "***** Generating files *****"
if [[ "$VERSION" =~ "v4_x" ]]; then
FILES_CNT=504
for n in {1..500}; do
echo "$n$n$n" > "$n.txt"
echo "$n$n$n" > "$n.txt"
done
else
FILES_CNT=304
for n in {1..300}; do
echo "$n$n$n" > "$n.txt"
for n in $(seq 1 $FILES_CNT); do
num=$(printf "%03d" ${n})
echo $num > "${num}.txt"
done
fi

Expand All @@ -57,7 +54,7 @@ echo $(ls -la | wc -l)
echo "***** Pushing file to the repo *****"
git add *
git commit -m push
git push -u origin dev
GOSH_TRACE=1 GOSH_PUSH_CHUNK=$BATCH_SIZE git push -u origin main &> ../trace_09_1.log

echo "***** cloning repo *****"
cd ..
Expand All @@ -68,8 +65,8 @@ git clone gosh://$SYSTEM_CONTRACT_ADDR/$DAO_NAME/$REPO_NAME $REPO_NAME"-clone"

echo "***** check repo *****"
cd "$REPO_NAME-clone"
git checkout dev
cur_ver=$(ls -la | wc -l)

cur_ver=$(ls -l | sed 1d | wc -l)
if [ "$cur_ver" != "$FILES_CNT" ]; then
echo "WRONG NUMBER OF FILES"
exit 1
Expand Down
2 changes: 2 additions & 0 deletions tests/set-vars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ tonos-cli config --url $NETWORK
set -x
# Should exist VersionConrtroler and SystemContract contracts

export VERSION_CONTROLLER=`cat $GOSH_PATH/VersionController.addr`
echo "export VERSION_CONTROLLER=$VERSION_CONTROLLER" >> env.env
export SYSTEM_CONTRACT_ADDR=`cat $GOSH_PATH/SystemContract.addr`
echo "export SYSTEM_CONTRACT_ADDR=$SYSTEM_CONTRACT_ADDR" >> env.env

Expand Down
3 changes: 2 additions & 1 deletion tests/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ function wait_account_active {
contract_addr=$1
is_ok=0
while [ $SECONDS -lt $stop_at ]; do
status=`tonos-cli -j -u $NETWORK account $contract_addr | jq -r '."'"$contract_addr"'".acc_type'`
# status=`tonos-cli -j -u $NETWORK account $contract_addr | jq -r '."'"$contract_addr"'".acc_type'`
status=`tonos-cli -j -u $NETWORK account $contract_addr | jq -r .acc_type`
if [ "$status" = "Active" ]; then
is_ok=1
echo account is active
Expand Down
8 changes: 4 additions & 4 deletions v6_x/v6.1.0/git-remote-gosh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ opentelemetry = {version = "0.18.0", features = ["rt-tokio"]}
opentelemetry-otlp = {version = "0.11.0", features = ["grpc-tonic"]}
opentelemetry-semantic-conventions = "0.10.0"
primitive-types = '0.12.1'
proc-macro2 = "=1.0.52"
# proc-macro2 = "=1.0.52"
reqwest-middleware = "0.2.0"
reqwest-tracing = "0.4.0"
rmp-serde = "1.1.1"
Expand Down Expand Up @@ -107,14 +107,14 @@ version = '1.21.2'
[dependencies.ton_client]
git = 'https://github.com/gosh-sh/ever-sdk.git'
default-features = false
features = ['std', 'rustls-tls-webpki-roots']
features = ['std']
package = 'ton_client'
tag = "1.43.1-rustls"
tag = "1.44.3"

[dependencies.ton_sdk]
git = 'https://github.com/gosh-sh/ever-sdk.git'
package = 'ton_sdk'
tag = "1.43.1-rustls"
tag = "1.44.3"

[dependencies.zstd]
default-features = false
Expand Down
147 changes: 112 additions & 35 deletions v6_x/v6.1.0/git-remote-gosh/src/blockchain/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@ pub use crate::abi as gosh_abi;
use crate::blockchain::{default_callback, BlockchainService, GoshContract};
use async_trait::async_trait;
use std::{
collections::hash_map::DefaultHasher,
hash::{Hash, Hasher},
sync::Arc,
time::{Duration, Instant},
};
use ton_client::{
abi::{CallSet, ParamsOfEncodeMessage, ResultOfEncodeMessage, Signer},
abi::{CallSet, ParamsOfEncodeMessage, ResultOfEncodeMessage, Signer, FunctionHeader},
processing::{
ParamsOfProcessMessage, ParamsOfSendMessage, ResultOfProcessMessage, ResultOfSendMessage,
MessageSendingParams, ParamsOfProcessMessage, ParamsOfSendMessage,
ResultOfProcessMessage, ResultOfSendMessage, ParamsOfSendMessages,
},
};
use tracing::Instrument;

#[async_trait]
pub(super) trait BlockchainCall {
pub trait BlockchainCall {
async fn call<C>(
&self,
contract: &C,
Expand All @@ -36,6 +39,22 @@ pub(super) trait BlockchainCall {
) -> anyhow::Result<SendMessageResult>
where
C: ContractInfo + Sync;

async fn send_messages(
&self,
messages: &Vec<(String, Option<BlockchainContractAddress>)>,
wait_until: u32,
) -> anyhow::Result<String>;

async fn construct_boc<C>(
&self,
contract: &C,
function_name: &str,
args: Option<serde_json::Value>,
expire: Option<u32>,
) -> anyhow::Result<(String, String)>
where
C: ContractInfo + Sync;
}

#[async_trait]
Expand Down Expand Up @@ -119,40 +138,11 @@ impl BlockchainCall for Everscale {
args,
expected_address,
);
let call_set = match args {
Some(value) => CallSet::some_with_function_and_input(function_name, value),
None => CallSet::some_with_function(function_name),
};
let signer = match contract.get_keys() {
Some(key_pair) => Signer::Keys {
keys: key_pair.to_owned(),
},
None => Signer::None,
};

let ResultOfEncodeMessage {
message,
message_id,
address,
..
} = ton_client::abi::encode_message(
Arc::clone(self.client()),
ParamsOfEncodeMessage {
abi: contract.get_abi().to_owned(),
address: Some(String::from(contract.get_address().clone())),
call_set,
signer,
deploy_set: None,
processing_try_index: None,
signature_id: None,
},
)
.await?;
let (message_id, message) =
self.construct_boc(contract, function_name, args, None).await?;

tracing::trace!(
"sending message ({message_id}) to {}",
contract.get_address()
);
tracing::trace!("sending message ({message_id}) to {}", contract.get_address());
let ResultOfSendMessage {
shard_block_id,
sending_endpoints,
Expand Down Expand Up @@ -197,4 +187,91 @@ impl BlockchainCall for Everscale {
};
Ok(call_result)
}

async fn send_messages(
&self,
messages: &Vec<(String, Option<BlockchainContractAddress>)>,
wait_until: u32,
) -> anyhow::Result<String> {
let messages_num = messages.len();
let mut hasher = DefaultHasher::new();
Hash::hash_slice(messages, &mut hasher);
let qkey = format!("{:x}", hasher.finish());
let messages: Vec<MessageSendingParams> = messages
.iter()
.map(|(boc, addr)| MessageSendingParams {
boc: boc.to_string(),
wait_until,
user_data: if let Some(addr) = addr {
Some(serde_json::json!({"expected_address": addr}))
} else {
None
},
})
.collect();

let params = ParamsOfSendMessages {
messages,
monitor_queue: Some(qkey.to_string())
};
ton_client::processing::send_messages(self.client().clone(), params).await?;
tracing::trace!("sent {} messages", messages_num);
Ok(qkey)
}

#[instrument(level = "info", skip_all)]
async fn construct_boc<C>(
&self,
contract: &C,
function_name: &str,
args: Option<serde_json::Value>,
expire: Option<u32>,
) -> anyhow::Result<(String, String)>
where
C: ContractInfo + Sync,
{
tracing::trace!(
"message BOC constructing: contract.address: {:?}, function: {}, args: {:?}",
contract.get_address().clone(),
function_name,
args,
);
let call_set = match args {
Some(value) => Some(CallSet {
function_name: function_name.into(),
header: Some(FunctionHeader {
expire,
..Default::default()
}),
input: Some(value)
}),
None => CallSet::some_with_function(function_name),
};
let signer = match contract.get_keys() {
Some(key_pair) => Signer::Keys {
keys: key_pair.to_owned(),
},
None => Signer::None,
};

let ResultOfEncodeMessage {
message_id,
message,
..
} = ton_client::abi::encode_message(
Arc::clone(self.client()),
ParamsOfEncodeMessage {
abi: contract.get_abi().to_owned(),
address: Some(String::from(contract.get_address().clone())),
call_set,
signer,
deploy_set: None,
processing_try_index: None,
signature_id: None,
},
)
.await?;

Ok((message_id, message))
}
}
3 changes: 1 addition & 2 deletions v6_x/v6.1.0/git-remote-gosh/src/blockchain/commit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ pub async fn get_set_commit_created_at_time(
is_internal: true,
..Default::default()
},
)
.await?;
)?;

tracing::trace!("Decoded message `{}`", decoded.name);
if decoded.name == "setCommit" {
Expand Down
3 changes: 1 addition & 2 deletions v6_x/v6.1.0/git-remote-gosh/src/blockchain/commit/save.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,7 @@ pub async fn find_messages(
is_internal: true,
..Default::default()
},
)
.await;
);
got_new_messages = true;
already_processed_messages.insert(message.id.clone(), true);

Expand Down
13 changes: 6 additions & 7 deletions v6_x/v6.1.0/git-remote-gosh/src/blockchain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub struct AddrVersion {
}

#[derive(Deserialize, Debug)]
struct CallResult {
pub struct CallResult {
#[serde(rename = "id")]
trx_id: String,
status: u8,
Expand All @@ -126,7 +126,7 @@ struct CallResult {
}

#[derive(Deserialize, Debug)]
struct SendMessageResult {
pub struct SendMessageResult {
shard_block_id: String,
message_id: String,
sending_endpoints: Vec<String>,
Expand Down Expand Up @@ -444,8 +444,7 @@ async fn run_static(
boc,
cache_type: BocCacheType::Pinned { pin: pin },
},
)
.await?;
)?;
// write lock
{
let mut refs = PINNED_CONTRACT_BOCREFS.write().await;
Expand Down Expand Up @@ -767,7 +766,7 @@ pub async fn calculate_boc_hash(context: &EverClient, code: &str) -> anyhow::Res
let params = ParamsOfGetBocHash {
boc: code.to_owned(),
};
let ResultOfGetBocHash { hash } = get_boc_hash(Arc::clone(context), params).await?;
let ResultOfGetBocHash { hash } = get_boc_hash(Arc::clone(context), params)?;
Ok(hash)
}

Expand All @@ -794,7 +793,7 @@ pub async fn calculate_contract_address(
};

let ResultOfEncodeInitialData { data } =
encode_initial_data(Arc::clone(context), params).await?;
encode_initial_data(Arc::clone(context), params)?;

let params = ParamsOfEncodeStateInit {
code: Some(code.to_owned()),
Expand All @@ -803,7 +802,7 @@ pub async fn calculate_contract_address(
};

let ResultOfEncodeStateInit { state_init } =
encode_state_init(Arc::clone(context), params).await?;
encode_state_init(Arc::clone(context), params)?;

let hash = calculate_boc_hash(context, &state_init).await?;

Expand Down
Loading