Skip to content

Commit

Permalink
chore: add full documentation to all crates (#210)
Browse files Browse the repository at this point in the history
* chore: common, config + derive doc updates

* chore: driver doc updates

* chore: update engine docs

* chore: update l1 docs

* chore: update network docs

* chore: update rpc docs

* chore: update runner docs

* chore: update telemetry + version docs

* chore: update docs based on clippy warnings

* fix: typos picked up by codespell
  • Loading branch information
zilayo authored Feb 12, 2024
1 parent e09d327 commit 82e2c51
Show file tree
Hide file tree
Showing 37 changed files with 689 additions and 47 deletions.
2 changes: 1 addition & 1 deletion docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This contains a simple docker setup for running magi and op-geth.

Begin by copying `.env.default` to `.env`. You can set the network to sync to by changing the `NETWORK` value (supported options are optimism-goerli and base-goerli). Make sure to set the `L1_RPC_URL` value to a valid RPC URL for the L1 being used by the given network. If you are running in production, you may also want to set a secure `JWT_SECRET` value. You can create a new secret by running `openssl rand -hex 32`.

To run both magi and op-geth together, run `docker compose up`. To run just op-geth without magi for local developement, run `COMPOSE_PROFILES=no-magi docker compose up`
To run both magi and op-geth together, run `docker compose up`. To run just op-geth without magi for local development, run `COMPOSE_PROFILES=no-magi docker compose up`

## Troubleshooting
If you are getting `permission denied` errors when attempting to run `docker-compose`, try `sudo docker compose` instead. This is often required when running docker depending on how it was installed.
2 changes: 1 addition & 1 deletion docs/devnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ NETWORK=devnet

# To avoid potential conflicts with the default ports in the OP devnet, it's recommended to modify the RPC ports.

# The exeuction client Auth RPC port.
# The execution client Auth RPC port.
EXECUTION_CLIENT_AUTH_RPC_PORT=5551

# The execution client RPC port.
Expand Down
23 changes: 23 additions & 0 deletions src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ use crate::engine::ExecutionPayload;
/// Selected block header info
#[derive(Debug, Clone, Copy, Eq, PartialEq, Default, Serialize, Deserialize)]
pub struct BlockInfo {
/// The block hash
pub hash: H256,
/// The block number
pub number: u64,
/// The parent block hash
pub parent_hash: H256,
/// The block timestamp
pub timestamp: u64,
}

Expand All @@ -28,8 +32,11 @@ pub struct RawTransaction(pub Vec<u8>);
/// L1 epoch block
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
pub struct Epoch {
/// The block number
pub number: u64,
/// The block hash
pub hash: H256,
/// The block timestamp
pub timestamp: u64,
}

Expand All @@ -50,6 +57,7 @@ impl From<BlockInfo> for Value {
impl TryFrom<Block<Transaction>> for BlockInfo {
type Error = eyre::Report;

/// Converts a [Block] to [BlockInfo]
fn try_from(block: Block<Transaction>) -> Result<Self> {
let number = block
.number
Expand Down Expand Up @@ -78,6 +86,7 @@ impl From<Epoch> for Value {
}

impl From<&ExecutionPayload> for BlockInfo {
/// Converts an [ExecutionPayload] to [BlockInfo]
fn from(value: &ExecutionPayload) -> Self {
Self {
number: value.block_number.as_u64(),
Expand All @@ -88,25 +97,37 @@ impl From<&ExecutionPayload> for BlockInfo {
}
}

/// Represents the `setL1BlockValues` transaction inputs included in the first transaction of every L2 block.
pub struct AttributesDepositedCall {
/// The L1 block number of the corresponding epoch this belongs to.
pub number: u64,
/// The L1 block timestamp of the corresponding epoch this belongs to.
pub timestamp: u64,
/// The L1 block basefee of the corresponding epoch this belongs to.
pub basefee: U256,
/// The L1 block hash of the corresponding epoch this belongs to.
pub hash: H256,
/// The L2 block's position within the epoch.
pub sequence_number: u64,
/// A versioned hash of the current authorized batcher sender.
pub batcher_hash: H256,
/// The current L1 fee overhead to apply to L2 transactions cost computation. Unused after Ecotone hard fork.
pub fee_overhead: U256,
/// The current L1 fee scalar to apply to L2 transactions cost computation. Unused after Ecotone hard fork.
pub fee_scalar: U256,
}

/// A type alias for the `setL1BlockValues` function parameter types
type SetL1BlockValueInput = (u64, u64, U256, H256, u64, H256, U256, U256);
/// The `setL1BlockValues` human-readable ABI
const L1_BLOCK_CONTRACT_ABI: &str = r#"[
function setL1BlockValues(uint64 _number,uint64 _timestamp, uint256 _basefee, bytes32 _hash,uint64 _sequenceNumber,bytes32 _batcherHash,uint256 _l1FeeOverhead,uint256 _l1FeeScalar) external
]"#;

impl TryFrom<Bytes> for AttributesDepositedCall {
type Error = eyre::Report;

/// Decodes and converts the given bytes (calldata) into [AttributesDepositedCall].
fn try_from(value: Bytes) -> Result<Self> {
let abi = BaseContract::from(parse_abi_str(L1_BLOCK_CONTRACT_ABI)?);

Expand Down Expand Up @@ -135,6 +156,7 @@ impl TryFrom<Bytes> for AttributesDepositedCall {
}

impl From<&AttributesDepositedCall> for Epoch {
/// Converts [AttributesDepositedCall] to an [Epoch] consisting of the number, hash & timestamp of the corresponding L1 epoch block.
fn from(call: &AttributesDepositedCall) -> Self {
Self {
number: call.number,
Expand All @@ -145,6 +167,7 @@ impl From<&AttributesDepositedCall> for Epoch {
}

impl Decodable for RawTransaction {
/// Decodes RLP encoded bytes into [RawTransaction] bytes
fn decode(rlp: &Rlp) -> Result<Self, DecoderError> {
let tx_bytes: Vec<u8> = rlp.as_val()?;
Ok(Self(tx_bytes))
Expand Down
Loading

0 comments on commit 82e2c51

Please sign in to comment.