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

Relayer mvp #631

Merged
merged 51 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
5b2cf6d
add new relayer clone
Voxelot Sep 14, 2022
1924530
delete a bunch of stuff not needed for POA
Voxelot Sep 14, 2022
a70b00a
started integration test with middleware
freesig Sep 14, 2022
0826e46
add some more test stuff
Voxelot Sep 14, 2022
00c8e63
adds await synced
freesig Sep 14, 2022
0c6ad20
use watch instead of notifier
Voxelot Sep 14, 2022
a4b841f
added middleware
freesig Sep 14, 2022
e995881
add some basic provider usage
Voxelot Sep 14, 2022
9d33be5
test passes for gettting da height
freesig Sep 14, 2022
4092e7f
add test for downloading messages and adding them to the database
freesig Sep 14, 2022
f0b4a31
adds test for committed block
freesig Sep 15, 2022
163ddae
add state transitions and sync updates
freesig Sep 15, 2022
6230ff8
test state and mock events and calls
freesig Sep 16, 2022
4ff514e
add ability to track pending transactions
freesig Sep 19, 2022
dc22e2c
fix future
freesig Sep 19, 2022
2c8a91d
cleanup and refactor
freesig Sep 20, 2022
ff1f21f
Merge branch 'master' of github.com:FuelLabs/fuel-core into relayer-mvp
freesig Sep 20, 2022
1e7d1dc
Merge branch 'master' of github.com:FuelLabs/fuel-core into relayer-mvp
freesig Sep 20, 2022
71af8ad
remove old relayer
freesig Sep 20, 2022
a9290be
Merge branch 'relayer-mvp' of github.com:FuelLabs/fuel-core into rela…
freesig Sep 20, 2022
b387746
add flake to generate bindings
freesig Sep 21, 2022
e646e05
update to new abi
freesig Sep 21, 2022
6d42e06
add missing commit block calls
freesig Sep 26, 2022
cc60be4
remove whitespace
freesig Sep 26, 2022
336d59f
Merge branch 'master' of github.com:FuelLabs/fuel-core into relayer-mvp
freesig Sep 27, 2022
ea4ebab
lint toml
freesig Sep 27, 2022
7c4f7e2
refactor to for upcoming contract spec
freesig Sep 29, 2022
9d077d1
commit before removing publish
freesig Sep 29, 2022
8333531
remove publish and add pagination to get logs
freesig Sep 30, 2022
b0e5a2e
Add comments
freesig Sep 30, 2022
870cfe5
remove debug
freesig Sep 30, 2022
8a68c99
fix toml
freesig Sep 30, 2022
aae10d5
Merge branch 'master' of github.com:FuelLabs/fuel-core into relayer-mvp
freesig Sep 30, 2022
ac55d77
handle relayer errors properly and test syncing
freesig Oct 3, 2022
816a834
clippy
freesig Oct 3, 2022
400c361
make tokio tests run in paused mode
freesig Oct 3, 2022
0efb2b8
only construct relayer if the relayer url is set
freesig Oct 3, 2022
cae04d9
Merge branch 'master' of github.com:FuelLabs/fuel-core into relayer-mvp
freesig Oct 3, 2022
cbf8e9d
update readme
freesig Oct 3, 2022
fca85f2
fix range and put logs into db inside stream
freesig Oct 3, 2022
00aedac
move nix to another pr
freesig Oct 3, 2022
ee62172
documentation
freesig Oct 4, 2022
e8cbe98
Merge branch 'master' of github.com:FuelLabs/fuel-core into relayer-mvp
freesig Oct 4, 2022
6ddf46a
add deploy height to relayer
freesig Oct 4, 2022
6471789
fix db
freesig Oct 5, 2022
b5d31b0
record height on pages
freesig Oct 6, 2022
7cc05d0
make pages type consume if empty
freesig Oct 6, 2022
fd1bd2e
make syncing eth loop configurable and only log every N seconds
freesig Oct 6, 2022
3c292d2
Merge branch 'master' into relayer-mvp
freesig Oct 6, 2022
9cf3d40
fix config
freesig Oct 6, 2022
2062a35
Merge branch 'master' into relayer-mvp
Voxelot Oct 6, 2022
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
122 changes: 122 additions & 0 deletions Cargo.lock

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

2 changes: 0 additions & 2 deletions fuel-core-bft/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use fuel_core_interfaces::{
},
block_producer::BlockProducer,
p2p::P2pRequestEvent,
relayer,
};
use parking_lot::Mutex;
use std::sync::Arc;
Expand Down Expand Up @@ -35,7 +34,6 @@ impl Service {

pub async fn start(
&self,
_relayer: relayer::Sender,
_p2p_consensus: mpsc::Sender<P2pRequestEvent>,
_block_producer: Arc<dyn BlockProducer>,
_block_importer_sender: mpsc::Sender<ImportBlockMpsc>,
Expand Down
115 changes: 5 additions & 110 deletions fuel-core-interfaces/src/relayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ use crate::{
fuel_types::Address,
},
db::{
DelegatesIndexes,
KvStoreError,
Messages,
StakingDiffs,
ValidatorsSet,
},
model::{
BlockHeight,
Expand Down Expand Up @@ -74,133 +71,31 @@ impl StakingDiff {
// From relayer perspective messages are just inserted when they get finalized.
// But for ValidatorSet, it is little bit different.
#[async_trait]
pub trait RelayerDb:
StorageMutate<Messages, Error = KvStoreError>
+ StorageMutate<ValidatorsSet, Error = KvStoreError>
+ StorageMutate<DelegatesIndexes, Error = KvStoreError>
+ StorageMutate<StakingDiffs, Error = KvStoreError>
+ Send
+ Sync
{
pub trait RelayerDb: StorageMutate<Messages, Error = KvStoreError> + Send + Sync {
/// Add bridge message to database. Messages are not revertible.
async fn insert_message(&mut self, message: &CheckedMessage) {
let _ = self
.storage::<Messages>()
.insert(message.id(), message.as_ref());
}

/// Insert difference make on staking in this particular DA height.
async fn insert_staking_diff(
&mut self,
da_height: DaBlockHeight,
stakes: &StakingDiff,
) {
let _ = self.storage::<StakingDiffs>().insert(&da_height, stakes);
}

/// Query delegate index to find list of blocks that delegation changed
/// iterate over list of indexed to find height that is less but closest to da_height
/// Query that block StakeDiff to find actual delegation change.
async fn get_first_lesser_delegation(
&mut self,
delegate: &Address,
da_height: DaBlockHeight,
) -> Option<HashMap<ValidatorId, ValidatorStake>> {
let delegate_index = self
.storage::<DelegatesIndexes>()
.get(delegate)
.expect("Expect to get data without problem")?;
let mut last_da_height = 0;
for index in delegate_index.iter() {
if *index >= da_height {
break
}
last_da_height = **index;
}
// means that first delegate is in future or not existing in current delegate_index
if last_da_height == 0 {
return None
}
// get staking diff
let staking_diff = self
.storage::<StakingDiffs>()
.get(&last_da_height.into())
.expect("Expect to get data without problem")?;

staking_diff.delegations.get(delegate).unwrap().clone()
}

async fn append_delegate_index(
&mut self,
delegate: &Address,
da_height: DaBlockHeight,
) {
let new_indexes = if let Some(indexes) =
self.storage::<DelegatesIndexes>().get(delegate).unwrap()
{
let mut indexes = (*indexes).clone();
indexes.push(da_height);
indexes
} else {
vec![da_height]
};
self.storage::<DelegatesIndexes>()
.insert(delegate, &new_indexes)
.expect("Expect to insert without problem");
}

/// get stakes difference between fuel blocks. Return vector of changed (some blocks are not going to have any change)
async fn get_staking_diffs(
&self,
_from_da_height: DaBlockHeight,
_to_da_height: Option<DaBlockHeight>,
) -> Vec<(DaBlockHeight, StakingDiff)> {
Vec::new()
}

/// Apply validators diff to validator set and update validators_da_height. This operation needs
/// to be atomic.
async fn apply_validator_diffs(
&mut self,
da_height: DaBlockHeight,
changes: &HashMap<ValidatorId, (ValidatorStake, Option<ConsensusId>)>,
) {
// this is reimplemented inside fuel-core db to assure it is atomic operation in case of poweroff situation
for (address, stake) in changes {
let _ = self.storage::<ValidatorsSet>().insert(address, stake);
}
self.set_validators_da_height(da_height).await;
}

/// current best block number
async fn get_chain_height(&self) -> BlockHeight;

async fn get_sealed_block(&self, height: BlockHeight)
-> Option<Arc<SealedFuelBlock>>;

/// get validator set for current eth height
async fn get_validators(&self) -> ValidatorSet;

/// Set data availability block height that corresponds to current_validator_set
async fn set_validators_da_height(&self, block: DaBlockHeight);

/// Assume it is always set as initialization of database.
async fn get_validators_da_height(&self) -> DaBlockHeight;

/// set finalized da height that represent last block from da layer that got finalized.
async fn set_finalized_da_height(&self, block: DaBlockHeight);

/// Assume it is always set as initialization of database.
async fn get_finalized_da_height(&self) -> DaBlockHeight;

/// Until blocks gets committed to da layer it is expected for it to still contains consensus
/// votes and be saved in database until commitment is send to da layer and finalization period passes.
/// In case that committed_finalized_fuel_height is zero we need to return genesis block.
async fn get_last_committed_finalized_fuel_height(&self) -> BlockHeight;
/// Get the last fuel block height that was published to the da layer.
async fn get_last_published_fuel_height(&self) -> Option<BlockHeight>;

/// Set last committed finalized fuel height this means we are safe to remove consensus votes from db
/// as from this moment they are not needed any more
async fn set_last_committed_finalized_fuel_height(&self, block_height: BlockHeight);
/// Set the last fuel block height that was published to the da layer.
async fn set_last_published_fuel_height(&self, block_height: BlockHeight);
}

pub type ValidatorSet = HashMap<ValidatorId, (ValidatorStake, Option<ConsensusId>)>;
Expand Down
1 change: 1 addition & 0 deletions fuel-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ tracing-subscriber = { version = "0.3", features = [
"env-filter",
"json",
] }
url = "2.2"
uuid = { version = "1.1", features = ["v4"] }

[dev-dependencies]
Expand Down
Loading