Skip to content

Commit 853d67d

Browse files
MitchTurnerxgreenx
andauthored
PoA Leader Lock for Block Production (#3203)
## Linked Issues/PRs <!-- List of related issues/PRs --> ## Description <!-- List of detailed changes --> The goal with this change is to allow multiple authority nodes to be live without causing contention on who should produce the next block. Introduced the `LeaderLeasePort`: ```rs #[async_trait::async_trait] pub trait LeaderLeasePort: Send + Sync { async fn can_produce_block(&self, height: BlockHeight) -> anyhow::Result<bool>; async fn release_lease(&self) -> anyhow::Result<()>; } ``` Where each block producer can check if the lease is available before producing a block. On shutdown, it will always release the lease as well. The implementation is `RedisLeaderLeaseAdapter`, where we use a lease on a Redis server. The server can have its own ttl for the lease so if a block producer dies before releasing the lease, it can still be grabbed by the other producers :) ## Checklist - [ ] Breaking changes are clearly marked as such in the PR description and changelog - [ ] New behavior is reflected in tests - [ ] [The specification](https://github.com/FuelLabs/fuel-specs/) matches the implemented behavior (link update PR if changes are needed) ### Before requesting review - [ ] I have reviewed the code myself - [ ] I have created follow-up issues caused by this PR and linked them here ### After merging, notify other teams [Add or remove entries as needed] - [ ] [Rust SDK](https://github.com/FuelLabs/fuels-rs/) - [ ] [Sway compiler](https://github.com/FuelLabs/sway/) - [ ] [Platform documentation](https://github.com/FuelLabs/devrel-requests/issues/new?assignees=&labels=new+request&projects=&template=NEW-REQUEST.yml&title=%5BRequest%5D%3A+) (for out-of-organization contributors, the person merging the PR will do this) - [ ] Someone else? --------- Co-authored-by: Green Baneling <XgreenX9999@gmail.com>
1 parent 697e692 commit 853d67d

File tree

32 files changed

+1459
-127
lines changed

32 files changed

+1459
-127
lines changed

.changes/changed/3203.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add lease port for PoA adapter to allow multiple producers to be live but only one leader.

.github/workflows/ci.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,44 @@ jobs:
235235
- name: Run integration tests for kms only
236236
run: cargo test -p fuel-core-tests --features aws-kms -- kms
237237

238+
leader-lock-integration-tests:
239+
name: Leader Lock Integration Tests (w/Redis)
240+
needs:
241+
- lint-toml-files
242+
- prevent-openssl
243+
- rustfmt
244+
- check-changelog
245+
runs-on: buildjet-4vcpu-ubuntu-2204
246+
timeout-minutes: 45
247+
env:
248+
RUSTFLAGS: -D warnings
249+
steps:
250+
- uses: actions/checkout@v4
251+
- name: Install Rust
252+
uses: dtolnay/rust-toolchain@master
253+
with:
254+
toolchain: ${{ env.RUST_VERSION }}
255+
- name: Install Redis
256+
run: |
257+
sudo apt-get update
258+
sudo apt-get install -y redis-server
259+
- name: Start Redis
260+
run: |
261+
redis-server --daemonize yes
262+
redis-cli ping
263+
- name: Run leader lock integration tests
264+
run: |
265+
echo "REDIS_URL=${REDIS_URL:-redis://127.0.0.1:6379} REDIS_DB=${REDIS_DB:-0} LEADER_LOCK_KEY_PREFIX=${LEADER_LOCK_KEY_PREFIX:-<unset>}"
266+
env | sort | grep -Ei 'REDIS|LEADER|LOCK|FUEL' || true
267+
(timeout 90s redis-cli MONITOR | stdbuf -oL grep -E 'SELECT|SET|PEXPIRE|DEL|leader|lock' || true) &
268+
cargo test --package fuel-core-tests --test integration_tests leader_lock --features leader_lock -- --test-threads=1 --nocapture
269+
238270
verifications-complete:
239271
needs:
240272
- cargo-verifications
241273
- publish-crates-check
242274
- cargo-test-kms
275+
- leader-lock-integration-tests
243276
runs-on: ubuntu-latest
244277
steps:
245278
- run: echo "pass"

Cargo.lock

Lines changed: 86 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)