forked from InjectiveLabs/peggo
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add main loops diagrams (#275)
* add BatchRequesterLoop diagram * add comments to EthOracleMainLoop BatchRequesterLoop * add EthOracleMainLoop diagram * add diagram to readme * add EthSignerMainLoop diagram * fix typo * add RelayerMainLoop diagram * cl++ * add diagrams to codecov ignore
- Loading branch information
1 parent
5f6e27f
commit fdba565
Showing
17 changed files
with
249 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,5 +47,6 @@ ignore: | |
- "types/*.pb.go" | ||
- "test/*" | ||
- "test/**/*" | ||
- "diagrams/**/*" | ||
- "scripts/" | ||
- "contrib" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Peggo diagrams | ||
|
||
- All the peggo main loops are going to have an specific diagram associated | ||
with it | ||
- All the diagrams were made using [mermaid](https://mermaid-js.github.io/mermaid/#/) | ||
- Can be edited in [mermaid.live](https://mermaid.live/) | ||
|
||
## Loops | ||
|
||
### EthOracleMainLoop | ||
|
||
- The `EthOracleMainLoop` responsible for making sure that Ethereum events are | ||
retrieved from the Ethereum blockchain and ferried over to Cosmos where they | ||
will be used to issue tokens or process batches | ||
|
||
![diagram](./mermaid-diagram-eth_oracle_main_loop-2022_04_26.png) | ||
|
||
- Code for this diagram is in `diagrams/loop_EthOracleMainLoop.mermaid` | ||
|
||
### BatchRequesterLoop | ||
|
||
- This loop really means that peggo checks with umee if there is any batch of tokens | ||
that needs to be batched to ethereum (It doesn't actually sends that batch) it just | ||
request to cosmos that this batch is built to be bridged in another loop | ||
|
||
- This loop is where peggo looks at the BatchFees and uses the query endpoint `BatchFees` | ||
to iterate over the send to Eth tx pool for each token type, the relayer can then | ||
observe the price for the ERC20 tokens being relayed on a dex and compute the gas | ||
cost of executing the batch (via `eth_call()`) as well as the gas cost of | ||
liquidating the earnings on a dex if desired. Once a relayer determines that a | ||
batch is good and profitable it can send a `MsgRequestBatch` and the batch will | ||
be created for the relayer to relay. | ||
|
||
- `MsgRequestBatch` is a message anyone can send that requests a batch of transactions | ||
to send across the bridge be created for whatever block height this message is | ||
included in. This acts as a coordination point, the handler for this message | ||
looks at the `AddToOutgoingPool` tx's in the store and generates a batch, also | ||
available in the store tied to this message. The validators then grab this batch, | ||
sign it, submit the signatures with a MsgConfirmBatch before a relayer | ||
can finally submit the batch | ||
|
||
![diagram](./mermaid-diagram-batch_requester_loop-2022_04_25.png) | ||
|
||
- Code for this diagram is in `diagrams/loop_BatchRequesterLoop.mermaid` | ||
|
||
### EthSignerMainLoop | ||
|
||
- The `EthSignerMainLoop` responsible for making sure that transaciton batches | ||
and validator set are signed and confirmed and sent to the cosmos so that | ||
afterwards they can be relayed and sent to the ethereum smartcontract | ||
|
||
![diagram](./mermaid-diagram-eth_signer_main_loop-2022_05_24.png) | ||
|
||
- Code for this diagram is in `diagrams/loop_EthSignerMainLoop.mermaid` | ||
|
||
### RelayerMainLoop | ||
|
||
- The `RelayerMainLoop` responsible for getting the latest valset available | ||
and updating it on the ethereum smartcontract if needed. Also gets all the pending | ||
transaction batches and it's signatures from cosmos and send it to the ethereum if | ||
that batch of token is profitable, wasn't sent yet by another node (checking the | ||
nonce) and it is not currently in the eth node node mempool. | ||
|
||
![diagram](./mermaid-diagram-relayer_main_loop-2022_05_24.png) | ||
|
||
- Code for this diagram is in `diagrams/loop_RelayerMainLoop.mermaid` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
sequenceDiagram | ||
title: BatchRequesterLoop | ||
|
||
Peggo->>+Cosmos: BatchFees queries the batch fees | ||
Cosmos-->>-Peggo: return the batches from unbatched pool | ||
Peggo->>+Oracle: GetPrice of all unbatched tokens | ||
Oracle-->>-Peggo: return all token prices and symbols of unbatched tokens | ||
Peggo->>+Ethereum: Get tokens decimals of unbatched tokens | ||
Ethereum-->>-Peggo: return decimals of each unbatched tokens | ||
Peggo->>+Cosmos: Get token denom from erc20 address | ||
Cosmos-->>-Peggo: returns denoms of each token | ||
Peggo->>+Peggo: Calculate batch profitability | ||
Peggo-->>-Peggo: Batch is profitable | ||
Peggo->>+Cosmos: SendRequestBatch for each token denom | ||
Cosmos->>+Cosmos: Generates a batch tx to send across the bridge | ||
Cosmos-->>-Cosmos: Validators grab batch and sign an MsgConfirmBatch | ||
Cosmos->>-Peggo: Continue in RelayerMainLoop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
sequenceDiagram | ||
title: EthOracleMainLoop | ||
|
||
Peggo->>+Cosmos: queries Gravity Bridge Params | ||
Cosmos-->>-Peggo: returns current params | ||
|
||
Peggo-->>Peggo: Smart Contract is confirmed | ||
|
||
Peggo->>+Peggo: Init GetLastCheckedBlock | ||
|
||
Peggo->>+Cosmos: LastEventNonceByAddr gets last nonce from this addr | ||
Cosmos-->>-Peggo: returns last nonce from this addr | ||
|
||
Peggo->>+Ethereum: GetLastBlock | ||
Ethereum-->>-Peggo: returns last block | ||
|
||
Peggo->>+Ethereum: get sendToCosmosEvent, sendToCosmosEvent, TransactionBatchExecuted,<br> ERC20Deployed, ValsetUpdatedEvent events from last block | ||
Ethereum-->>-Peggo: returns all events | ||
|
||
Peggo->>-Peggo: End GetLastCheckedBlock | ||
|
||
Peggo->>+Peggo: Init CheckForEvents | ||
Peggo->>+Ethereum: Get Last block | ||
Ethereum-->>-Peggo: returns last block | ||
|
||
Peggo->>+Ethereum: get all events ERC20Deployed, SendToCosmos,<br> TransactionBatchExecuted, ValsetUpdatedEvent | ||
Ethereum-->>-Peggo: returns all the events | ||
|
||
Peggo->>+Cosmos: get LastEventNonceByAddr | ||
Cosmos-->>-Peggo: returns the last nonce for that addr | ||
|
||
Peggo-->>Peggo: filter all the events from the nonce | ||
|
||
Peggo->>+Cosmos: broadcast all the eth events | ||
Cosmos-->>-Peggo: waits for tx to be included in block | ||
|
||
Peggo-->>-Peggo: End CheckForEvents |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
sequenceDiagram | ||
title: EthSignerMainLoop | ||
|
||
Peggo->>+Ethereum: queries Gravity Bridge ID | ||
Ethereum-->>-Peggo: returns current gravityID | ||
|
||
Peggo->>+Cosmos: LastPendingValsetRequestByAddr | ||
Peggo->>+Cosmos: AccFromAddress | ||
Cosmos-->>-Peggo: returns the address | ||
Cosmos-->>-Peggo: returns the validator set snapshots it has not yet signed | ||
|
||
Peggo->>+Peggo: Init Loop for each unsigned Valset | ||
Peggo->>+Cosmos: SendValsetConfirm sends an confirmation for a validator <br> "MsgValsetConfirm" that sends signatures over to the validator | ||
Cosmos-->>-Peggo: If 66%+ sent the MsgValsetConfirm then we can <br>submit the new validator set to ethereum | ||
Peggo->>-Peggo: Ends Loop | ||
|
||
Peggo->>+Cosmos: get the LastPendingBatchRequestByAddr | ||
Cosmos-->>-Peggo: returns last pending transaction batch unsigned | ||
|
||
Peggo->>+Peggo: Init Loop for each unsigned transaction batch | ||
Peggo->>+Cosmos: SendBatchConfirm send an MsgConfirmBatch<br> with txs and eth signature | ||
Cosmos-->>-Peggo: Cosmos validators order the txs of <br>highest to lowest fee in txqueue | ||
Peggo->>-Peggo: Ends Loop | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
sequenceDiagram | ||
title: RelayerMainLoop | ||
|
||
Peggo->>+Peggo: FindLatestValset | ||
Peggo->>+Ethereum: GetLastBlockNumber | ||
Ethereum-->>-Peggo: returns the block number | ||
|
||
Peggo->>+Ethereum: GetValsetNonce gets the last valset nonce | ||
Ethereum-->>-Peggo: returns the last nonce on eth | ||
|
||
Peggo->>+Cosmos: ValsetRequest gets the last valset nonce | ||
Cosmos-->>-Peggo: returns the last nonce on cosmos | ||
|
||
Peggo->>+Ethereum: FilterValsetUpdatedEvent gets the last ValsetUpdatedEvent | ||
Ethereum-->>-Peggo: returns the last ValsetUpdatedEvent | ||
|
||
Peggo->>Peggo: Builds all the ValsetUpdatedEvent and <br>reverse the order | ||
Peggo->>Peggo: CheckIfValsetsDiffer Checks the last valset <br>from eth if the change is meaningfull | ||
|
||
Peggo-->>-Peggo: returns the latests possible valset | ||
|
||
Peggo->>+Peggo: RelayValsets | ||
|
||
Peggo->>+Cosmos: LastValsetRequests gets the last valset request | ||
Cosmos-->>-Peggo: returns the last valset request on cosmos | ||
|
||
Peggo->>+Cosmos: findLatestValidValset gets the last valid valset | ||
Cosmos-->>-Peggo: returns the lastest valid valset and signatures | ||
|
||
Peggo->>+Ethereum: GetValsetNonce gets the last valset nonce | ||
Ethereum-->>-Peggo: returns the last nonce | ||
|
||
Peggo->>Peggo: Check if nonce wasn't already submitted | ||
|
||
Peggo-->>-Peggo: submit the updated Valset as <br>an Ethereum transaction if is needed | ||
|
||
Peggo->>+Peggo: getBatchesAndSignatures | ||
|
||
Peggo->>+Cosmos: OutgoingTxBatches gets the outgoing transactions | ||
Cosmos-->>-Peggo: returns the OutgoingTxBatches of the gravity module | ||
|
||
Peggo->>+Cosmos: BatchConfirms foreach batch | ||
Cosmos-->>-Peggo: returns all the signatures for the given batch | ||
|
||
Peggo->>+Ethereum: EncodeTransactionBatch checks with the gravity <br>contract if the signatures are good to be sent | ||
Ethereum-->>-Peggo: returns error if any | ||
|
||
Peggo->>Peggo: Builds the batches of transactions<br> as possibleBatches | ||
|
||
Peggo-->>-Peggo: returns possible batches <br>to be relayed | ||
|
||
Peggo->>+Peggo: RelayBatches | ||
|
||
Peggo->>+Ethereum: GetLastBlockNumber | ||
Ethereum-->>-Peggo: returns the last block number | ||
|
||
Peggo->>+Ethereum: GetTxBatchNonce | ||
Ethereum-->>-Peggo: returns the latest transaction batch nonce | ||
|
||
Peggo->>Peggo: Checks for the last submitted <br>nonce on eth with the batch nonce | ||
|
||
Peggo->>+Ethereum: EncodeTransactionBatch encodes the <br>batch with signature (v, r, s) | ||
Ethereum-->>-Peggo: returns encoded batch as bytes | ||
|
||
Peggo->>+Ethereum: EstimateGas calculates the gas usage of the tx to be sent | ||
Ethereum-->>-Peggo: returns the estimated gas cost | ||
|
||
Peggo->>Peggo: Checks if the batch is <br>profitable using the oracles and <br>checking the price of each asset | ||
|
||
Peggo->>+Ethereum: IsPendingTxInput check if the tx is pending in the mempool | ||
Ethereum-->>-Peggo: returns whether or not the tx is already there | ||
|
||
Peggo->>+Ethereum: SendTx sends the transaction to<br> ethereum with the encoded batch | ||
Ethereum-->>-Peggo: returns the transaction hash | ||
|
||
Peggo-->>-Peggo: relayes all the possible <br>batches to ethereum |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters