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

Fix/improve sdk #603

Merged
merged 27 commits into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3c03fd0
feat: add doc store
imotai Jun 13, 2023
bf6b69b
Merge remote-tracking branch 'origin/main'
imotai Jun 14, 2023
50dd93a
Merge remote-tracking branch 'origin/main'
imotai Jun 19, 2023
99d8aad
Merge remote-tracking branch 'origin/main'
imotai Jun 21, 2023
ea84758
Merge remote-tracking branch 'origin/main'
imotai Jun 23, 2023
3dc6d3a
Merge remote-tracking branch 'origin/main'
imotai Jun 25, 2023
954d205
Merge remote-tracking branch 'origin/main'
imotai Jun 26, 2023
a70c835
Merge remote-tracking branch 'origin/main'
imotai Jun 29, 2023
4da2934
Merge remote-tracking branch 'origin/main'
imotai Jun 29, 2023
e2938c9
Merge remote-tracking branch 'origin/main'
imotai Jul 2, 2023
afaaa0c
Merge remote-tracking branch 'origin/main'
imotai Jul 3, 2023
3851509
Merge remote-tracking branch 'origin/main'
imotai Jul 4, 2023
20e1d28
Merge remote-tracking branch 'origin/main'
imotai Jul 4, 2023
7d74a39
Merge remote-tracking branch 'origin/main'
imotai Jul 8, 2023
e1d65c8
Merge remote-tracking branch 'origin/main'
imotai Jul 9, 2023
f55f1b8
Merge remote-tracking branch 'origin/main'
imotai Jul 11, 2023
73ac492
Merge remote-tracking branch 'origin/main'
imotai Jul 17, 2023
4ea9ea2
Merge remote-tracking branch 'origin/main'
imotai Jul 20, 2023
6d4dae2
Merge remote-tracking branch 'origin/main'
imotai Jul 20, 2023
a03b34f
Merge remote-tracking branch 'origin/main'
imotai Jul 21, 2023
a991f2c
Merge remote-tracking branch 'origin/main'
imotai Jul 24, 2023
072c1bf
Merge remote-tracking branch 'origin/main'
imotai Jul 28, 2023
01efd5b
Merge remote-tracking branch 'origin/main'
imotai Aug 9, 2023
7ded300
Merge remote-tracking branch 'origin/main'
imotai Aug 11, 2023
366bbb4
fix: improve the add doc error
imotai Aug 12, 2023
36dc0e7
fix: use github runner
imotai Sep 3, 2023
ff95ca4
fix: add protobuf
imotai Sep 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ jobs:

coverage:
name: test
#runs-on: ubuntu-latest
runs-on: [self-hosted, linux, x64]
runs-on: ubuntu-latest
#runs-on: [self-hosted, linux, x64]
steps:
- name: Checkout repository
uses: actions/checkout@v3
Expand All @@ -51,8 +51,8 @@ jobs:
- name: Setup Build env
run: |
ROOT_DIR=`pwd`
#sudo apt-get install protobuf-compiler -y
#yarn global add arlocal_db3
sudo apt-get install protobuf-compiler -y
yarn global add arlocal_db3
cd ${ROOT_DIR}/metadata && yarn install
cd ${ROOT_DIR}/metadata && npx hardhat test
test -e ${ROOT_DIR}/metadata/artifacts/contracts/DB3MetaStore.sol/DB3MetaStore.json && cp -f ${ROOT_DIR}/metadata/artifacts/contracts/DB3MetaStore.sol/DB3MetaStore.json ${ROOT_DIR}/abi/
Expand Down
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ members = [
"src/sdk",
"src/event"
]

[workspace.dependencies]
fastcrypto = {git = "https://github.com/MystenLabs/fastcrypto", rev = "306465d4fe04f6c26359d885f3b0a548b661de40"}
ethers = {git="https://github.com/imotai/ethers-rs", rev="d526191b7972e8cf4412fee8b71cbf42e0ce7995"}
Expand Down
8 changes: 7 additions & 1 deletion sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ export type {
MutationResult,
QueryResult,
} from './store/types'
export { addDoc, updateDoc, deleteDoc, queryDoc, getDoc } from './store/document_v2'
export {
addDoc,
updateDoc,
deleteDoc,
queryDoc,
getDoc,
} from './store/document_v2'

export { SystemConfig, SystemStatus, Version } from './proto/db3_base'
export {
Expand Down
12 changes: 11 additions & 1 deletion sdk/src/store/document_v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,13 @@ export async function updateDoc(
}
}

/**
* Add a document to the collection.
*
* @param col The collection to add the document to.
* @param doc The document to add.
* @returns The ID of the newly added document.
*/
export async function addDoc(col: Collection, doc: DocumentData) {
const documentMutation: DocumentMutation = {
collectionName: col.name,
Expand All @@ -250,6 +257,7 @@ export async function addDoc(col: Collection, doc: DocumentData) {
payload,
col.db.client.nonce.toString()
)

if (response.code == 0 && response.items.length > 0) {
col.db.client.nonce += 1
return {
Expand All @@ -259,6 +267,8 @@ export async function addDoc(col: Collection, doc: DocumentData) {
id: response.items[0].value,
}
} else {
throw new Error('fail to create collection')
throw new Error(
'fail to addDoc, maybe you can syncAccountNonce to resolve the problem'
)
}
}
4 changes: 2 additions & 2 deletions sdk/tests/client_v2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
deleteDoc,
updateDoc,
queryDoc,
getDoc
getDoc,
} from '../src/store/document_v2'
import {
createFromPrivateKey,
Expand Down Expand Up @@ -383,7 +383,7 @@ describe('test db3.js client module', () => {
try {
const doc = await getDoc(collection, 1000000000000)
except(1).toBe(0)
} catch(e) {}
} catch (e) {}
}

{
Expand Down
7 changes: 7 additions & 0 deletions src/node/src/rollup_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,15 @@ impl RollupExecutor {
return Ok(());
}
let now = Instant::now();

info!(
"the next rollup start block {} and the newest block {current_block}",
last_end_block
);

self.pending_start_block
.store(last_end_block, Ordering::Relaxed);

self.pending_end_block
.store(current_block, Ordering::Relaxed);
let mutations = self
Expand Down Expand Up @@ -305,6 +308,7 @@ impl RollupExecutor {
self.pending_data_size.store(0, Ordering::Relaxed);
self.pending_mutations.store(0, Ordering::Relaxed);
}

let (id, reward, num_rows, size) = ar_toolbox
.compress_and_upload_record_batch(
tx,
Expand All @@ -318,13 +322,15 @@ impl RollupExecutor {
let (evm_cost, tx_hash) = meta_store
.update_rollup_step(id.as_str(), network_id)
.await?;

let tx_str = format!("0x{}", hex::encode(tx_hash.as_bytes()));

info!("the process rollup done with num mutations {num_rows}, raw data size {memory_size}, compress data size {size} and processed time {} id {} ar cost {} and evm tx {} and cost {}", now.elapsed().as_secs(),
id.as_str(), reward,
tx_str.as_str(),
evm_cost.as_u64()
);

let record = RollupRecord {
end_block: current_block,
raw_data_size: memory_size as u64,
Expand All @@ -338,6 +344,7 @@ impl RollupExecutor {
evm_tx: tx_str,
evm_cost: evm_cost.as_u64(),
};

self.storage
.add_rollup_record(&record)
.map_err(|e| DB3Error::RollupError(format!("{e}")))?;
Expand Down
Loading