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

config: add new fork for testnet at block#1916000 #993

Merged
merged 31 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
109f63c
chore(deps): bump openssl-src from 111.22.0+1.1.1q to 111.25.0+1.1.1t
dependabot[bot] Feb 8, 2023
89e6226
chore: fix web3-unit-tests (#977)
Flouse Feb 10, 2023
6110103
Fix CI (#980)
jjyr Feb 11, 2023
9dac5ea
chore: build image with optional SMT trie feature
Flouse Feb 11, 2023
52bf8f4
chore: update GODWOKEN_KICKER_REF in godwoken-tests.yml
Flouse Feb 11, 2023
cf2fe66
feat(gwos-evm): fix fuzzing test
magicalne Jan 18, 2023
32f66b6
fix(CI): specify an older version of ubuntu
magicalne Jan 31, 2023
00f61e0
fix(CI): create corpus folder
magicalne Jan 31, 2023
c6ee526
chore: remove useless include
magicalne Jan 31, 2023
cdb1b09
fix: c format
magicalne Jan 31, 2023
2abf775
chore: decrease timeout of fuzz testing
magicalne Jan 31, 2023
38f1add
fix(fuzz test): dead lock
magicalne Jan 31, 2023
2f6433a
chore: turn extern fn to unsafe extern fn
magicalne Feb 3, 2023
c8e209d
chore: data hashes were stored mistakenly and ignore Cargo.lock in si…
magicalne Feb 6, 2023
701050c
feat(CI): run fuzz test every hour
magicalne Feb 7, 2023
26feb50
chore: upgrade actions/cache@v3
magicalne Feb 7, 2023
ab67adc
Merge pull request #984 from godwokenrises/1.12-rc
jjyr Feb 14, 2023
70b8608
doc: new monorepo README (#979)
jjyr Feb 14, 2023
9b0aa9c
feat: send pending upgrade l1 tx at certain height
jjyr Feb 3, 2023
f1e7456
fix: refresh contracts deps after sending l1 upgrade tx
jjyr Feb 8, 2023
24395a1
fix: correct l1 upgrading height, remove local cell injection
jjyr Feb 13, 2023
bee8737
fix: fix macos build
jjyr Feb 13, 2023
50eedc0
chore(gwos-evm): bump Polyjuice version to v1.5.3
Flouse Feb 13, 2023
7a18765
chore(builtin): add godwoken-polyjuice-v1.5.3/generator
Flouse Feb 13, 2023
9b54720
chore: manual build Godwoken with gw-config/no-builtin feature
Flouse Feb 14, 2023
c188e8c
Set GODWOKEN_KICKER_REF=develop in workflows/godwoken-tests.yml
Flouse Feb 14, 2023
690f381
chore(CI): update fuzz duration
magicalne Feb 14, 2023
46fdb22
chore(CI): overwrite MAX_FUZZ_TIME for pr
magicalne Feb 14, 2023
db78df1
Update the ref of submodule "crates/builtin-binaries/builtin" (#987)
Flouse Feb 18, 2023
024f2a3
chore: update the ref of reusable-integration-test-v1.yml to develop
Flouse Feb 18, 2023
0e6b3ac
config: add new fork for testnet at block#1916000
Flouse Feb 20, 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
2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ jobs:

integration-test:
needs: docker-build-push
uses: godwokenrises/godwoken-tests/.github/workflows/reusable-integration-test-v1.yml@yq
uses: godwokenrises/godwoken-tests/.github/workflows/reusable-integration-test-v1.yml@develop
with:
extra_github_env: |
GODWOKEN_IMAGE="${{ needs.docker-build-push.outputs.image_name }}:${{ needs.docker-build-push.outputs.image_tag }}"
2 changes: 1 addition & 1 deletion .github/workflows/godwoken-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:
POLYJUICE_GIT_URL=https://github.com/${{ github.repository }}
POLYJUICE_GIT_CHECKOUT=${{ github.ref }}
GODWOKEN_KICKER_REPO=godwokenrises/godwoken-kicker
GODWOKEN_KICKER_REF=refs/pull/343/merge
GODWOKEN_KICKER_REF=develop
41 changes: 17 additions & 24 deletions .github/workflows/gwos-evm-fuzz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ on:
pull_request:
paths:
- 'gwos-evm/**'
schedule:
- cron: 0 * * * *

jobs:
build-and-run-fuzzing:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
defaults:
run:
working-directory: gwos-evm
Expand All @@ -31,9 +33,9 @@ jobs:
key: ${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }}
- name: Install moleculec
run: |
export MOLC_VERSION=$(cat deps/godwoken-scripts/c/Makefile | egrep "MOLC_VERSION :=" | awk '{print $3}')
export MOLC_VERSION=$(cat ../gwos/c/Makefile | egrep "MOLC_VERSION :=" | awk '{print $3}')
test "$(moleculec --version)" = "Moleculec $MOLC_VERSION" \
|| CARGO_TARGET_DIR=target/ cargo install moleculec --version $MOLC_VERSION --force
|| CARGO_TARGET_DIR=target/ cargo install moleculec --version $MOLC_VERSION
- name: Cache LLVM and Clang
id: cache-llvm
uses: actions/cache@v3
Expand All @@ -47,7 +49,7 @@ jobs:
uses: actions/cache@v3
with:
path: |
polyjuice-tests/fuzz/corpus-cache
gwos-evm/polyjuice-tests/fuzz/corpus-cache
key: corpus-${{ env.DATETIME }}
restore-keys: |
corpus
Expand All @@ -58,30 +60,21 @@ jobs:
version: "11.0"
cached: ${{ steps.cache-llvm.outputs.cache-hit }}

- name: test_rlp on x86 with sanitizers
working-directory: ./gwos-evm/polyjuice-tests/fuzz
run: make build/test_rlp && ./build/test_rlp
- name: test_contracts on x86 with sanitizers
working-directory: ./gwos-evm/polyjuice-tests/fuzz
run: make build/test_contracts && ./build/test_contracts
- name: Set fuzzing duration for 1h
run: echo "MAX_FUZZ_TIME=3600" >> $GITHUB_ENV

- name: Set MAX_FUZZ_TIME for different branches
run: |
if [[ ${{ github.event_name == 'pull_request' }} ]]; then
echo "MAX_FUZZ_TIME=6" >> $GITHUB_ENV
elif [[ ${{ startsWith(github.base_ref, 'fuzz') }} ]]; then
echo "MAX_FUZZ_TIME=3600" >> $GITHUB_ENV
else
echo "MAX_FUZZ_TIME=60" >> $GITHUB_ENV
fi
- name: Set fuzzing duration for 1m
if: github.event_name == 'pull_request'
run: echo "MAX_FUZZ_TIME=60" >> $GITHUB_ENV

- name: Fuzzing Polyjuice Generator 1 hour
- name: Fuzzing Polyjuice
working-directory: gwos-evm/polyjuice-tests/fuzz
run: |
mkdir -p corpus-cache
mkdir -p corpus
ls corpus-cache
make build/polyjuice_generator_fuzzer && \
./build/polyjuice_generator_fuzzer corpus corpus-cache \
make build/fuzzer && \
./build/fuzzer corpus corpus-cache \
-max_total_time=$MAX_FUZZ_TIME -timeout=120 \
-max_len=25000 -rss_limit_mb=0
# Max data buffer size: 24KB < 25000 bytes
Expand All @@ -90,7 +83,7 @@ jobs:
working-directory: gwos-evm/polyjuice-tests/fuzz
run: |
mkdir -p corpus-new
./build/polyjuice_generator_fuzzer -merge=1 corpus-new corpus-cache corpus
./build/fuzzer -merge=1 corpus-new corpus-cache corpus
rm -rf corpus-cache
mv corpus-new corpus-cache

Expand All @@ -109,4 +102,4 @@ jobs:
with:
name: corpus
path: |
polyjuice-tests/fuzz/corpus-cache/*
gwos-evm/polyjuice-tests/fuzz/corpus-cache/*
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ crates/benches/smt_data/db/
crates/tests/mem_block/
gwos-evm/deps/ckb-binary-patcher/
gwos-evm/polyjuice-tests/Cargo.lock
gwos-evm/polyjuice-tests/fuzz/gw-syscall-simulator/Cargo.lock

node_modules
web3/node_modules/
Expand Down
18 changes: 16 additions & 2 deletions Cargo.lock

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

69 changes: 64 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,71 @@
# Godwoken

> Godwoken v1 release note: [docs/v1-release-note.md](https://github.com/nervosnetwork/godwoken/blob/develop/docs/v1-release-note.md)
Welcome to the Godwoken Monorepo! This repository is the home of the Godwoken project.

Godwoken is an optimistic roll-up solution built upon the [Nervos CKB](https://docs.nervos.org/). It is designed to be configurable in many regards and continues to evolve:
Godwoken is a key component of Nervos' layer-2, working in conjunction with the Rollup technique to create a scalable, EVM-compatible layer for the Nervos network. With Godwoken, developers can build decentralized applications (dApps) on the Ethereum Virtual Machine (EVM) and run them on the Nervos network, increasing the scalability and efficiency of the network.

* In the current implementation, a fixed group of block producers can issue new layer 2 blocks. In the future, we plan for a Proof of Stake solution, where we can evolve the block producing to the decentralized processing.
* Currently, [polyjuice](https://github.com/nervosnetwork/godwoken-polyjuice) is integrated into Godwoken for an Ethereum compatible solution. However, Godwoken, at its core, only provides a flexible [programming interface](https://github.com/nervosnetwork/godwoken-scripts/blob/master/c/gw_def.h). A result of this is that any account-based blockchain model can be integrated with Godwoken this way. Similar to Polyjuice on Godwoken, we could also have EOS on Godwoken, Libra on Godwoken, etc.
Godwoken provides a solution for dApp builders who seek the advantages of Ethereum - Like its community, good tools, and documentation - but not the drawbacks that Ethereum faces, such as network congestion, high gas fees, oversaturation and scalability issues.


## Repository Structure

This monorepo contains all the packages and libraries necessary to develop and run Godwoken. The packages are organized into the following directories:

- `crates`: Contains the Rust code for Godwoken node. This is where developers can find the main Godwoken offchain code.
- `web3`: Web3 adapter layer, contains a web server providing web3 compatible RPC, and a block indexing program.
- `gwos`:
- `contracts`: Contains layer-1 contracts used to verify Godwoken layer-2 state transition.
- `c`: The layer-2 builtin contraints and layer-2 syscalls.
- `gwos-evm`: The EVM layer on Godwoken, itself is a Godwoken layer-2 contract.

## Understanding the Components

Godwoken is comprised of several key components that work together to provide a scalable, EVM-compatible layer-2 solution for Nervos. Here's a brief overview of each component:

### Godwoken Node

The code in the `generator`, `mem-pool`, `block-producer` under the `/crates` directory are the backbone of Godwoken node. They define the logic and rules for the layer-2 node behavior, including the mechanism for submitting and processing transactions.

The `/crates/chain` contains an implement of the syncing mechanism that syncing layer-1 blocks from CKB's RPC.

The `/crates/challenge` contains WIP challenger implementation, which is a core part of the optimistic rollup. The challenger will be reimplemented with the interactive challenge technique to reduce the on-chain challenge cost. Until then, the Godwoken network is [half centralized](https://docs.godwoken.io/overview#decentralization-roadmap).

### GWOS scripts

GWOS contains CKB scripts under `/gwos/contracts`. These scripts run upon layer-1 to verify the Godwoken layer-2 state transition.

Godwoken's layer-2 state is compressed into a sparse-merkle-tree which is stored in a CKB cell. Read [GWOS Readme](gwos/README.md) to learn how GWOS scripts work.

### Layer-2 contracts

Layer-2 contracts are running upon Godwoken. A layer-2 contract can modify Godwoken's sparse-merkle-tree state via syscalls.

The `gwos/c/gw_def.h` contains syscall interfaces write in C. and `/gwos/c/contracts` contains three builtin layer-2 contracts.

Technically, the layer-2 contracts can be written in any programming language that can be compiled to RISC-V thanks to [CKB VM](https://github.com/nervosnetwork/ckb-vm)'s ability. But currently, Godwoken only provides an EVM programming interface for layer-2 developers.

### EVM

`/gwos-evm` contains an EVM implementation that can run upon CKB-VM, which itself is also a layer-2 contract.

## Public Networks
- [Godwoken Mainnet v1](https://docs.godwoken.io/connectionInfo#godwoken-mainnet-v1)
- [Godwoken Testnet v1](https://docs.godwoken.io/connectionInfo#godwoken-testnet-v1)

## Documentation
- https://docs.godwoken.io
- [Ethereum Compatible Web3 RPC](web3/docs/apis.md)

## Getting Started

### Start a local dev chain

[Godwoken kicker](https://github.com/godwokenrises/godwoken-kicker/blob/develop/docs/kicker-start.md) is a recommended tool to start a local dev chain inside docker containers.

### Start a read-only node

We put mainnet and testnet configs under [godwoken-info](https://github.com/godwokenrises/godwoken-info), you can run a Godwoken node with these config to start syncing with the testnet and the mainnet.

## License

Please follow this [documentation](https://docs.godwoken.io) to learn more about Godwoken.
Godwoken is open-source software licensed under the MIT license.
8 changes: 8 additions & 0 deletions crates/block-producer/src/block_producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ impl BlockProducer {
Ok(block_producer)
}

pub fn generator(&self) -> &Generator {
&self.generator
}

pub fn contracts_dep_manager(&self) -> &ContractsCellDepManager {
&self.contracts_dep_manager
}

#[instrument(skip_all, fields(retry_count = retry_count))]
pub async fn produce_next_block(
&self,
Expand Down
2 changes: 1 addition & 1 deletion crates/block-producer/src/challenger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ impl Challenger {

let err_str = err.to_string();
if err_str.contains(TRANSACTION_FAILED_TO_RESOLVE_ERROR) {
if let Err(err) = self.contracts_dep_manager.refresh().await {
if let Err(err) = self.contracts_dep_manager.refresh(None).await {
// Lets retry on next error
log::error!("[contracts dep] refresh failed {}", err);
}
Expand Down
82 changes: 81 additions & 1 deletion crates/block-producer/src/psc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use gw_types::{
};
use gw_utils::{
abort_on_drop::spawn_abort_on_drop, liveness::Liveness, local_cells::LocalCellsManager,
since::Since,
since::Since, RollupContext,
};
use tokio::{
signal::unix::{signal, SignalKind},
Expand Down Expand Up @@ -83,6 +83,12 @@ pub struct PSCContext {
pub liveness: Arc<Liveness>,
}

impl PSCContext {
fn rollup_context(&self) -> &RollupContext {
self.block_producer.generator().rollup_context()
}
}

impl SyncL1Context for PSCContext {
fn store(&self) -> &Store {
&self.store
Expand Down Expand Up @@ -252,6 +258,10 @@ async fn run(state: &mut ProduceSubmitConfirm) -> Result<()> {
let context = state.context.clone();
submit_handle.replace_with(tokio::spawn(async move {
loop {
submit_pending_l1_upgrade(&context)
.await
.with_context(|| "failed to submit pending l1 upgrade")?;

match submit_next_block(&context).await {
Ok(nh) => return Ok(nh),
Err(err) => {
Expand All @@ -271,6 +281,10 @@ async fn run(state: &mut ProduceSubmitConfirm) -> Result<()> {
let context = state.context.clone();
confirm_handle.replace_with(tokio::spawn(async move {
loop {
confirm_pending_l1_upgrade(&context)
.await
.with_context(|| "failed to confirm pending l1 upgrade")?;

match confirm_next_block(&context).await {
Ok(nh) => break Ok(nh),
Err(err) => {
Expand Down Expand Up @@ -736,6 +750,72 @@ async fn median_gte(rpc_client: &RPCClient, timestamp_millis: u64) -> Result<()>
Ok(())
}

/// Submit next pending l1 upgrade
async fn submit_pending_l1_upgrade(ctx: &PSCContext) -> Result<()> {
let snap = ctx.store.get_snapshot();
let block_number = snap
.get_last_submitted_block_number_hash()
.expect("last submitted")
.number()
.unpack()
+ 1;
drop(snap);

// find next l1 upgrade by block number
if let Some(l1_upgrade) = ctx
.rollup_context()
.fork_config
.pending_l1_upgrades
.iter()
.find(|l1_upgrade| l1_upgrade.height == block_number)
{
let tx: Transaction = l1_upgrade.signed_transaction.clone().into();
log::info!(
"sending l1 upgrade transaction 0x{}",
hex::encode(tx.calc_tx_hash().as_slice())
);

// We can't recover from errors when sending l1 upgrade tx, so we just throw it
send_transaction_or_check_inputs(&ctx.rpc_client, &tx).await?;
log::info!("tx sent");

// Refresh block producer's contracts deps
ctx.block_producer
.contracts_dep_manager()
.refresh(Some(tx))
.await?;
}
Ok(())
}

/// Confirm next pending l1 upgrade
async fn confirm_pending_l1_upgrade(ctx: &PSCContext) -> Result<()> {
let snap = ctx.store.get_snapshot();
let block_number = snap
.get_last_confirmed_block_number_hash()
.expect("last confirmed")
.number()
.unpack()
+ 1;
drop(snap);

// find next l1 upgrade by block number
if let Some(l1_upgrade) = ctx
.rollup_context()
.fork_config
.pending_l1_upgrades
.iter()
.find(|l1_upgrade| l1_upgrade.height == block_number)
{
let tx: Transaction = l1_upgrade.signed_transaction.clone().into();
// We can't recover from errors when confirming l1 upgrade tx,
// both deadcell error and unknwown cell is unacceptable, so we just throw it
poll_tx_confirmed(&ctx.rpc_client, &tx).await?;
log::info!("l1 upgrade tx confirmed");
}
Ok(())
}

/// Calculate a since whose timestamp > param timestamp_millis
fn greater_since(timestamp_millis: u64) -> Since {
Since::new_timestamp_seconds(timestamp_millis / 1000 + 1)
Expand Down
Loading