🌉x/bridge module
An overview of the x/bridge module
Last updated
An overview of the x/bridge module
Last updated
The x/bridge module
(dydx1zlefkpe3g0vvm9a4h0jf9000lmqutlh9jwjnsv
) is responsible for receiving bridged tokens from the Ethereum blockchain. It has an associated daemon
that knows about all “bridge events” that happened on Ethereum by making RPC calls to an Ethereum full node. Bridge events are logs emitted by the bridging smart-contract on Ethereum. Each event has a unique, sequentially-increasing id
.
A bridge event can be considered to be in one of the following states:
State | Description |
---|---|
MsgAcknowledgeBridges
This message is injected by the block proposer.
It should be rejected during ProcessProposal
if any of below is true
event IDs are not sequential
first event’s id
does not match NextAcknowledgeEventId
in state.
last event’s id
is not recognized yet.
any event’s content does not match what’s in state.
For each bridge event, it delays a MsgCompleteBridge (see below) using x/delaymsg module to be executed SafetyParams.delay_blocks blocks later.
MsgCompleteBridge
This message should only be sent by the x/delaymsg
module. It will mint tokens to the specified address by transferring from the bridge module account. The id
does not have to be verified.
PrepareProposal
Let the wall-clock time of the proposer be wallClock. Let the block timestamp be blockTimestamp. In order to ensure an upper-bound on liveness issues in the case that +⅓ of validators cannot properly get logs from an Ethereum node, we will often skip proposing bridge events at all. Since we expect the rate of bridge events to be much lower than 1 per v4 block, we use a combination of probabilistic (based on pseudo-randomness) and deterministic (based on time) skipping. Therefore, skip this step altogether (by proposing a bridge tx with empty bridge events) if either of the following:
rand.Uint32(1_000_000) < ProposeParams.skip_rate_ppm
blockTimestamp ≤ wallClock - ProposeParams.skip_if_block_delayed_by_duration
In PrepareProposal
, the proposer will inject one MsgAcknowledgeBridges
transaction that includes at most ProposeParams.max_bridges_per_block
bridge events (in order of id
), which need to satisfy following criteria
An id
greater-than-or-equal-to the NextAcknowledgeEventId
A recognizedAt ≤ wallClock - ProposeParams.propose_delay_duration
MsgUpdateEventParams
MsgUpdateSafetyParams
MsgUpdateProposeParams
GetRecognizedEventInfo
Returns the RecognizedEventInfo
from the BridgeEventManager
. This has the next event id
that has not yet been recognized by this node’s daemon. This also has the height of the highest Ethereum block from which a bridge event was recognized. These values are not in-consensus.
GetAcknowledgedEventInfo
Returns the AcknowledgedEventInfo
from state.
AcknowledgeBridges
For each bridge event, sends a message to the x/delay-msg
module, wrapping a MsgCompleteBridge
to be executed SafetyParams.delay_blocks
blocks in the future. Update AcknowledgedEventInfo
in state.
CompleteBridge
Processes a bridge event by transfering the appropriate tokens to the given address from bridge module account. The id
of the bridge is not validated as it should have already been validated by AcknowledgeBridges
.
GetEventParams
Returns the EventParams
from state.
GetSafetyParams
Returns the SafetyParams
from state.
GetProposeParams
Returns the ProposeParams
from state.
UpdateEventParams
Overwrites the EventParams
in state. Returns an error and does not update the params if they fail basic validation.
UpdateSafetyParams
Overwrites the SafetyParams in state. Returns an error and does not update the params if they fail basic validation.
UpdateProposeParams
Overwrites the ProposeParams in state. Returns an error and does not update the params if they fail basic validation.
AcknowledgedEventInfo
BridgeEventInfo
Stores information about the next event id
to acknowledge (next_id
). The bridge daemon should query for this event id
next.
Also stores the Ethereum block height of the most recently acknowledged event. Ethereum block heights strictly lower than this number do not have to be checked by the daemon.
In practice, these value should be set to positive numbers at genesis since some of the bridging events should be included in genesis state.
EventParams
EventParams
Stores parameters about which events to recognize and which tokens to mint. Used by the daemon to sanity-check information. Is not used directly by the module logic.
ProposeParams
ProposeParams
Holds the proposal parameters for the module.
SafetyParams
SafetyParams
Holds the safety parameters for the module.
The keeper stores the bridge events in a go-routine safe map which is keyed by id
.
EthMined
Included in the Ethereum blockchain
EthFinalized
Included in the Ethereum blockchain in a block that has been finalized
Recognized
Understood to be finalized by an individual validator’s bridge daemon
Not in consensus
dYdX Chain validators should only propose Recognized
events for inclusion in blocks after an additional waiting period (configured in the ProposeParams)
in order to give enough time for other validators to recognize the event
Acknowledged
Included in a block on the open-source v4 chain developed by dYdX (”v4”) by a proposer and validated with +2⁄3 weight
In consensus
Completed
Was Acknowledged
for a certain number of blocks
Has resulted in newly-minted tokens on v4
In consensus
The block-delay (configured in the SafetyParams
) gives the validators the chance to halt or hard-fork the chain in the disaster-case of accidentally recognizing an invalid event