Skip to content

Commit

Permalink
fix: Set attesters in Connection::adjust_genesis (BFT-489) (#2429)
Browse files Browse the repository at this point in the history
## What ❔

Sets the `attesters` field in `Genesis` when performing a re-genesis
adjustment after the node starts and detects that its configuration has
changed.

### Testing


#### Main node only

To see if attestations work at all, I configured an attester key for the
main node, and ran it with the following commands:

```shell
zk clean
zk init
zk server --components=api,tree,eth,state_keeper,housekeeper,commitment_generator,vm_runner_protective_reads,vm_runner_bwip,da_dispatcher,base_token_ratio_persister,consensus
```

Then I checked whether data was being added to the database:

```console
❯ psql -d postgres://postgres:notsecurepassword@localhost:5432/zksync_local 
psql (14.12 (Homebrew))
Type "help" for help.

zksync_local=# select count(1) from l1_batches_consensus;
 count 
-------
     2
(1 row)

zksync_local=# select * from l1_batches_consensus;
 l1_batch_number |                                                                                                                                                certificate                                                                                                                                                |         created_at         |         updated_at         
-----------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------+----------------------------
               0 | {"msg": {"hash": {"keccak256": "FXT6d23sjaIHHl8g1xhAv8vYLCvKmtaGgO3+3eFxC8Q="}, "number": "0"}, "signatures": [{"key": {"secp256k1": "A4snYq04KzUJC7QpkqP2RC1jhCXqVSjoAP/lqffUGFWJ"}, "sig": {"secp256k1": "1isW+az1GcoCDbjDhch9U5qakl6BMO033TWOQhdpAdFHV8MQbouVRqq3bTPUtROGYRVx1OkM61/BidaVhBS5JBw="}}]} | 2024-07-11 15:00:24.026841 | 2024-07-11 15:00:24.026841
               1 | {"msg": {"hash": {"keccak256": "L40KCOJ3fiy7B2V8CeXOjO/Vo/dKCs+EA9CFS9/dJLg="}, "number": "1"}, "signatures": [{"key": {"secp256k1": "A4snYq04KzUJC7QpkqP2RC1jhCXqVSjoAP/lqffUGFWJ"}, "sig": {"secp256k1": "aP1Lw3u8BvGvWyjHauiEqhYvmidviG2jfdQdltnXSpUUQ4pOhKyT2FmGvplIMQ74vQDZaCbA12ap5WtHEJZEvRs="}}]} | 2024-07-11 15:00:34.069316 | 2024-07-11 15:00:34.069316
(2 rows)
```

#### Main and external node

I added attester keys to the external node config as well and gave it
equal weights with the main node in the genesis spec, so they can only
sign a QC together.

Started an external node with the following commands:

```shell
zk env ext-node
zk config compile
zk db setup
zk external-node -- --enable-consensus
```

And checked that the batch QC are inserted into the database, signed by
both nodes:

```console
❯ psql -d postgres://postgres:notsecurepassword@localhost:5432/zksync_local -c "select * from l1_batches_consensus"
 l1_batch_number |                                                                                                                                                                                                                                             certificate                                                                                                                                                                                                                                             |         created_at         |         updated_at         
-----------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------+----------------------------
               1 | {"msg": {"hash": {"keccak256": "erxoTxCmDETYR8ro8YeKD1AOZrZnc6e+4oYoR6MGPow="}, "number": "1"}, "signatures": [{"key": {"secp256k1": "AzCRTkGyJftvhRjVJ48MAUqYYQGMgFT5u0JbtlOFOPHJ"}, "sig": {"secp256k1": "1osJ9pPa8hB4BKNN6U9MDKommLOOKJ3hNOLpHdsqWRJN5dooK+CflKwQAIUtwjGa22EhmGulKv1fQs3stmSt3Rs="}}, {"key": {"secp256k1": "A4snYq04KzUJC7QpkqP2RC1jhCXqVSjoAP/lqffUGFWJ"}, "sig": {"secp256k1": "xA8x0UcDq3ZultBn7ylM/G4+vRpsb+GQEbhUagAeZ2duvPRX5fOICR7z8k7wiJLine4/3abqcN/Uyn4FX97mpRw="}}]} | 2024-07-11 15:14:19.121081 | 2024-07-11 15:14:19.121081
(1 row)
```

It only signed the batch 1, not batch 0, because by the time I started
the external node the main node already created two batches, and
currently only the last vote counts. The certificate shows two items in
`signatures`.

## Why ❔

So that we can configure attesters (to sign L1 batches) on the stage 2
environment. Without this change the configured committee would be
ignored.

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [x] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [x] Tests for the changes have been added / updated.
- [x] Documentation comments have been added / updated.
- [x] Code has been formatted via `zk fmt` and `zk lint`.

---------

Co-authored-by: Bruno França <[email protected]>
  • Loading branch information
aakoshh and brunoffranca authored Jul 11, 2024
1 parent 5a48e10 commit ca4cb3c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
6 changes: 4 additions & 2 deletions core/node/consensus/src/storage/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,27 +237,29 @@ impl<'a> Connection<'a> {
.start_transaction(ctx)
.await
.wrap("start_transaction()")?;

let old = txn.genesis(ctx).await.wrap("genesis()")?;
if let Some(old) = &old {
if &config::GenesisSpec::from_genesis(old) == spec {
// Hard fork is not needed.
return Ok(());
}
}

tracing::info!("Performing a hard fork of consensus.");
let genesis = validator::GenesisRaw {
chain_id: spec.chain_id,
fork_number: old
.as_ref()
.map_or(validator::ForkNumber(0), |old| old.fork_number.next()),
first_block: txn.next_block(ctx).await.context("next_block()")?,

protocol_version: spec.protocol_version,
validators: spec.validators.clone(),
attesters: None,
attesters: spec.attesters.clone(),
leader_selection: spec.leader_selection.clone(),
}
.with_hash();

txn.try_update_genesis(ctx, &genesis)
.await
.wrap("try_update_genesis()")?;
Expand Down
13 changes: 9 additions & 4 deletions etc/env/consensus_config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
server_addr: '127.0.0.1:3054'
public_addr: '127.0.0.1:3054'
server_addr: "127.0.0.1:3054"
public_addr: "127.0.0.1:3054"
max_payload_size: 2500000
gossip_dynamic_inbound_limit: 1
# LOCALHOST TEST CONFIGURATION ONLY, don't copy to other environments.
genesis_spec:
chain_id: 1337
protocol_version: 1
validators:
- key: 'validator:public:bls12_381:b14e3126668ae79e689a2d65c56522889a3812ef5433097c33bd7af601b073dcdddf46e188883aa381725c49e08f90c705df1f78bf918e1978912cebeadff0d0084b1a4fe2ddee243e826348045f528803207f5de303c6a95bc1a701a190dbcf'
- key: "validator:public:bls12_381:b14e3126668ae79e689a2d65c56522889a3812ef5433097c33bd7af601b073dcdddf46e188883aa381725c49e08f90c705df1f78bf918e1978912cebeadff0d0084b1a4fe2ddee243e826348045f528803207f5de303c6a95bc1a701a190dbcf"
weight: 1
leader: "validator:public:bls12_381:b14e3126668ae79e689a2d65c56522889a3812ef5433097c33bd7af601b073dcdddf46e188883aa381725c49e08f90c705df1f78bf918e1978912cebeadff0d0084b1a4fe2ddee243e826348045f528803207f5de303c6a95bc1a701a190dbcf"
attesters:
- key: "attester:public:secp256k1:038b2762ad382b35090bb42992a3f6442d638425ea5528e800ffe5a9f7d4185589"
weight: 1
- key: "attester:public:secp256k1:0330914e41b225fb6f8518d5278f0c014a9861018c8054f9bb425bb6538538f1c9"
weight: 1
leader: 'validator:public:bls12_381:b14e3126668ae79e689a2d65c56522889a3812ef5433097c33bd7af601b073dcdddf46e188883aa381725c49e08f90c705df1f78bf918e1978912cebeadff0d0084b1a4fe2ddee243e826348045f528803207f5de303c6a95bc1a701a190dbcf'
6 changes: 4 additions & 2 deletions etc/env/consensus_secrets.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# 'validator:public:bls12_381:b14e3126668ae79e689a2d65c56522889a3812ef5433097c33bd7af601b073dcdddf46e188883aa381725c49e08f90c705df1f78bf918e1978912cebeadff0d0084b1a4fe2ddee243e826348045f528803207f5de303c6a95bc1a701a190dbcf'
validator_key: 'validator:secret:bls12_381:3cf20d771450fcd0cbb3839b21cab41161af1554e35d8407a53b0a5d98ff04d4'
validator_key: "validator:secret:bls12_381:3cf20d771450fcd0cbb3839b21cab41161af1554e35d8407a53b0a5d98ff04d4"
# 'node:public:ed25519:a9995979f228c91e4f387f7e141a9afe409196ee0c4fca0045c1c6b6e7892cb5'
node_key: 'node:secret:ed25519:9a40791b5a6b1627fc538b1ddecfa843bd7c4cd01fc0a4d0da186f9d3e740d7c'
node_key: "node:secret:ed25519:9a40791b5a6b1627fc538b1ddecfa843bd7c4cd01fc0a4d0da186f9d3e740d7c"
# 'attester:public:secp256k1:038b2762ad382b35090bb42992a3f6442d638425ea5528e800ffe5a9f7d4185589'
attester_key: "attester:secret:secp256k1:efc2431bd337d8ed1a16a21aa1f9916fade00cb9d1e849d493735df21e2d75ed"
4 changes: 3 additions & 1 deletion etc/env/en_consensus_secrets.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# 'node:public:ed25519:2621c2ae111901d4a9b46e96e64f71282b9209fc6b5e4df3d4208d3de28a482d'
node_key: 'node:secret:ed25519:19bc1ddd9fd2921d1b919e7dcfa465babdcf61a60a21e5df9b3f105bd9cfcb2c'
node_key: "node:secret:ed25519:19bc1ddd9fd2921d1b919e7dcfa465babdcf61a60a21e5df9b3f105bd9cfcb2c"
# 'attester:public:secp256k1:0330914e41b225fb6f8518d5278f0c014a9861018c8054f9bb425bb6538538f1c9'
attester_key: "attester:secret:secp256k1:899b0caa073f5db0a07e1fe953c94b05256f2c92fd03f0c33ef870622bc778ab"

0 comments on commit ca4cb3c

Please sign in to comment.