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

offchain processing macro and example for sov-nft-module #939

Merged
merged 35 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
5596ab5
offchain processing
dubbelosix Sep 27, 2023
3b9b547
BlockScout integration fixes (#917)
neysofu Sep 25, 2023
e6cd64a
modules_api: simplify public key definition (#918)
bkolad Sep 25, 2023
e718a55
`EVM`: Add missing docs (#914)
bkolad Sep 25, 2023
f1c399b
Cleanup prover docs/logs (#919)
preston-evans98 Sep 25, 2023
09b141a
Bump markdown from 1.0.0-alpha.13 to 1.0.0-alpha.14 (#924)
dependabot[bot] Sep 25, 2023
e5d2dd8
Bump rayon from 1.7.0 to 1.8.0 (#923)
dependabot[bot] Sep 25, 2023
6432983
Bump prost-build from 0.11.9 to 0.12.1 (#930)
dependabot[bot] Sep 25, 2023
3b13808
Bump parking_lot from 0.11.2 to 0.12.1 (#927)
dependabot[bot] Sep 25, 2023
6d81f3a
feat: use json as manifest constants instead of toml (#922)
vlopes11 Sep 25, 2023
2430281
Bump tungstenite from 0.20.0 to 0.20.1 (#931)
dependabot[bot] Sep 26, 2023
b406b94
EVM: Implement eth_call (#921)
orkunkilic Sep 27, 2023
7d08dce
cargo lock
dubbelosix Sep 27, 2023
425c480
some fixes
dubbelosix Sep 28, 2023
76c65a0
move common code into lib
dubbelosix Sep 28, 2023
5d2b981
added issue to the nft script
dubbelosix Sep 28, 2023
37c43b7
add nft cli binary to nft-utils
dubbelosix Sep 28, 2023
ee4f343
Revert "add nft cli binary to nft-utils"
dubbelosix Sep 29, 2023
317417d
move nft-utils back to sovereign/nft-utils and move sql to sql.rs
dubbelosix Sep 29, 2023
85ed254
remove un-necessary deps in nft-utils
dubbelosix Sep 29, 2023
d1eec17
Run tests with prover enabled. (#932)
bkolad Sep 27, 2023
fa58991
fix: require `native` when applicable for all targets (#937)
vlopes11 Sep 27, 2023
ce4b105
Remove default trait bound from Module (#941)
bkolad Sep 28, 2023
1e0c87c
Remove demo-rollup-local job from CI (#943)
bkolad Sep 28, 2023
1d8ac46
Delta's go first, remove `get` from StateCheckpoint (#953)
citizen-stig Sep 28, 2023
13b822e
Make genesis config serializable (#956)
preston-evans98 Sep 29, 2023
9ae8c3c
Introduce: `PublicKeyHex` in `sov-modules-api` (#954)
bkolad Sep 29, 2023
a514a5b
estimate-gas signed (#947)
orkunkilic Sep 29, 2023
19b4ea1
remove include and make it a module
dubbelosix Sep 29, 2023
45cc748
fix packages.yml
dubbelosix Sep 29, 2023
a45fab2
EVM: Implement account related RPC (#958)
orkunkilic Sep 29, 2023
261e6cb
feature: gas meter (#795)
vlopes11 Sep 29, 2023
e1bc28c
Read `accounts` genesis from a file. (#959)
bkolad Sep 29, 2023
564ee31
fix a wrong merge conflict
dubbelosix Sep 29, 2023
be181d5
Merge branch 'nightly' into dub/offchain_processing
dubbelosix Sep 29, 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
112 changes: 112 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ members = [

"utils/zk-cycle-macros",
"utils/zk-cycle-utils",
"utils/nft-utils",
"utils/bashtestmd",
"utils/nft-utils",

"module-system/sov-cli",
"module-system/sov-modules-stf-template",
Expand Down
5 changes: 5 additions & 0 deletions examples/demo-prover/methods/guest-celestia/Cargo.lock

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

5 changes: 5 additions & 0 deletions examples/demo-prover/methods/guest-mock/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 examples/demo-rollup/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ native = ["anyhow", "jsonrpsee", "serde", "serde_json", "tracing", "tokio", "tra
"sov-state/native", "sov-cli", "clap", "sov-celestia-adapter/native", "sov-db", "sov-sequencer", "sov-stf-runner/native",
"sov-modules-api/native", "sov-rollup-interface/native"]
bench = ["native", "async-trait", "borsh", "hex"]

offchain = ["demo-stf/offchain"]

[[bench]]
name = "rollup_bench"
Expand Down
1 change: 1 addition & 0 deletions examples/demo-stf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ rand = "0.8"

[features]
default = []
offchain = ["sov-nft-module/offchain"]
experimental = ["sov-evm/experimental", "reth-primitives"]
native = [
"sov-stf-runner/native",
Expand Down
33 changes: 33 additions & 0 deletions full-node/sov-sequencer/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,39 @@ impl SimpleClient {
Ok(())
}

/// Sends multiple transactions to the sequencer for immediate publication.
pub async fn send_transactions<Tx: BorshSerialize>(
&self,
txs: Vec<Tx>,
chunk_size: Option<usize>,
) -> Result<(), anyhow::Error> {
let serialized_txs: Vec<Vec<u8>> = txs
.into_iter()
.map(|tx| tx.try_to_vec())
.collect::<Result<_, _>>()?;

match chunk_size {
Some(batch_size) => {
for chunk in serialized_txs.chunks(batch_size) {
let response: String = self
.http_client
.request("sequencer_publishBatch", chunk.to_vec())
.await?;
info!("publish batch response for chunk: {:?}", response);
}
}
None => {
let response: String = self
.http_client
.request("sequencer_publishBatch", serialized_txs)
.await?;
info!("publish batch response: {:?}", response);
}
}

Ok(())
}

/// Get a reference to the underlying [`HttpClient`]
pub fn http(&self) -> &HttpClient {
&self.http_client
Expand Down
8 changes: 4 additions & 4 deletions full-node/sov-stf-runner/src/batch_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ where
current_batch_size += tx_len;
}

if txs.is_empty() {
bail!("No valid transactions are available");
}

for (tx, err) in dismissed {
warn!("Transaction 0x{} was dismissed: {:?}", hex::encode(tx), err);
}

if txs.is_empty() {
bail!("No valid transactions are available");
}

Ok(txs)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[package]
name = "sov-nft-module"
description = "A Sovereign SDK module for managing non-fungible tokens"
version = { workspace = true }
edition = { workspace = true }
authors = { workspace = true }
Expand All @@ -21,6 +22,10 @@ sov-modules-api = { path = "../../sov-modules-api" }
sov-modules-macros = {path = "../../sov-modules-macros"}
sov-state = { path = "../../sov-state" }

postgres = { version = "0.19.7", optional = true }
tokio = { version = "1.32.0", features=["full"], optional = true }
tracing = { workspace = true, optional = true }

[dev-dependencies]
sov-rollup-interface = { path = "../../../rollup-interface" }
sov-data-generators = { path = "../../utils/sov-data-generators" }
Expand All @@ -29,5 +34,6 @@ sov-nft-module = { version = "*", features = ["native"], path = "." }

[features]
default = []
offchain = ["postgres","tokio","tracing"]
native = ["serde_json", "jsonrpsee", "schemars", "sov-state/native", "sov-modules-api/native", ]
test = ["native"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
## Offchain testing
dubbelosix marked this conversation as resolved.
Show resolved Hide resolved

### Introduction
This readme outlines the steps to demonstrate the offchain processing functionality that is part of the `sov-nft-module`

### Steps
* Install postgres on your system
* Start the postgres terminal
* Create the tables necessary for offchain processing

```bash
psql postgres -f sovereign/module-system/module-implementations/sov-nft-module/src/init_db.sql
```
* The above command runs the `init_db.sql` script which creates 3 tables
* `collections` - tracking the NFT collections that have been created, their supply and other info
* `nfts` - tracking the individual NFTs, the `token_uri` pointing to offchain state and other info
* `top_owners` - tracks the number of NFTs of each collection that a user owns
* running the following query can show the top owners for a specific collection
```sql
SELECT owner, count
FROM top_owners
WHERE collection_address = (
SELECT collection_address
FROM collections
WHERE collection_name = 'your_collection_name'
)
ORDER BY count DESC
LIMIT 5;
```
* running the following query can show the largest owner for each collection
```sql
SELECT
collection_name,
owner,
count
FROM (
SELECT c.collection_name, t.owner, t.count,
RANK() OVER (PARTITION BY t.collection_address ORDER BY t.count DESC) as rank
FROM top_owners t
INNER JOIN collections c ON c.collection_address = t.collection_address
) sub
WHERE rank = 1;
```

* Run the demo rollup in offchain mode
```bash
rm -rf demo_data; POSTGRES_CONNECTION_STRING="postgresql://username:password@localhost/postgres" cargo run --features offchain -- --da-layer mock
```
* Explanation of the above command
* `rm -rf demo_data` is to wipe the rollup state. For testing its better to start with clean state
* `POSTGRES_CONNECTION_STRING` is to allow the offchain component of the `sov-nft-module` to connect to postgres instance
* `--features offchain` is necessary to enable offchain processing. Without the feature, the functions are no-ops
* `--da-layer mock` is used to run an in-memory local DA layer
* Run the NFT minting script
```bash
$ cd sovereign/utils/nft-utils
$ cargo run
```
* The above script creates 3 NFT collections, mints some NFTs to each collection
* The tables can be explored by connecting to postgres and running sample queries from above
Loading