Appearance
Engine API
This page describes the current version
The behavior can change between v0.x versions.
The Engine API connects the consensus client to the execution client. The consensus client sends each new block to Cinder, tells Cinder which block is the head and asks Cinder to build blocks. This page lists the methods that Cinder implements, the statuses it returns and the errors it gives.
Cinder serves the Engine API in engine mode (cinder --engine). For the flags of the authenticated port and the JWT secret, read Configuration and the command line reference.
Transport and authentication
The Engine API uses JSON-RPC 2.0 over HTTP/1.1. The server has these properties:
- One thread serves all requests. Requests on one connection get answers in the order they arrive. There is no fixed order between connections. The same thread executes blocks, so a request waits until the request before it is complete.
- The server keeps up to 64 keep-alive connections. A 65th connection closes the connection that was idle for the longest time. If none is idle, it gets HTTP status 429, and the server closes it. The server closes a new connection that sends no byte in 30 seconds, a connection that is idle for 120 seconds, a request whose headers do not arrive in 30 seconds, a request that stops for 30 seconds, and a client that does not read its response for 30 seconds. A request whose body is not complete 60 seconds after its first byte gets HTTP status 408.
- A connection that sends no request with a valid JWT closes 3 seconds after the server accepts it. At the limit, a new connection first closes the oldest connection that has no valid JWT. Thus connections without a valid JWT never close the connection of the consensus client or keep its new connections out.
- The server reads chunked request bodies. A header block larger than 64 KiB gets HTTP status 431. A request with a header line that is not valid, or with
Transfer-EncodingandContent-Lengthtogether, gets HTTP status 400. - A request body can have a size of up to 64 MB. A larger body gets the HTTP status 413.
- The server accepts a batch (a JSON array of requests) and answers each request in it.
Every request must have the header Authorization: Bearer <token>. The token is a JSON Web Token with these properties:
- The algorithm is HS256. Cinder refuses any other algorithm,
noneincluded. - The secret is the 32-byte key in the JWT file, as hexadecimal text. The file can start with
0x. This is the same file format that reth and the consensus clients use. - The
iatclaim (issued at) must be within 60 seconds of the clock of the node.
A request without a valid token gets the HTTP status 401.
Methods
| Method | What it does |
|---|---|
engine_exchangeCapabilities | Returns the list of the methods in this table. |
engine_newPayloadV1 to V4 | Gives a new block to the node. The node executes it and returns a payload status. |
engine_forkchoiceUpdatedV1 to V3 | Sets the head, the safe block and the finalized block. With payload attributes, it starts to build a block. |
engine_getPayloadV4, V5 | Returns a block that the node built. |
engine_getBlobsV1, V2 | Returns blobs from the transaction pool. |
engine_getClientVersionV1 | Returns the client code CN, the name Cinder and the version. |
The same port also answers eth_chainId, eth_blockNumber and eth_syncing. eth_syncing always returns false. Cinder does not serve engine_getPayloadBodiesByHashV1 and engine_getPayloadBodiesByRangeV1. These calls get the error -32601. engine_newPayloadV5 and later versions, and engine_forkchoiceUpdatedV4 and later versions, belong to the Amsterdam fork. Cinder does not implement Amsterdam, so these calls always get the error -38005 (Unsupported fork). Read Amsterdam.
Versions and forks
Each version of engine_newPayload belongs to one fork. Cinder finds the fork from the timestamp of the payload before it reads anything else.
| Fork of the payload | Version that Cinder accepts |
|---|---|
| Paris | engine_newPayloadV1 |
| Shanghai | engine_newPayloadV2 |
| Cancun | engine_newPayloadV3 |
| Prague, Osaka and the BPO forks | engine_newPayloadV4 |
| Amsterdam and later | None. The answer is the error -38005. |
A call with a different version gets the error -38005 (Unsupported fork). A payload of an early version must not have the fields of a later version. For example, a V1 payload with withdrawals gets the error -32602.
engine_getPayloadV4 returns Prague blocks and engine_getPayloadV5 returns Osaka blocks. engine_getPayloadV1 to V3 get the error -38005 for a payload ID that the node has, because Cinder builds blocks for Prague and later forks only. For a payload ID that the node does not have, they get the error -38001, as reth.
engine_forkchoiceUpdatedV1, V2 and V3 have one implementation. Payload attributes must have the V3 form, with withdrawals and parentBeaconBlockRoot.
Amsterdam
This version does not implement the Amsterdam fork. Mainnet has no Amsterdam time yet, so by default the node has no Amsterdam time. With --amsterdam-time T, the node refuses each payload with a timestamp of T or later:
engine_newPayloadwith such a timestamp gets the error -38005. The node reads the timestamp before it decodes the payload, so the new header fields of Amsterdam do not cause a decode error.- A forkchoice update with payload attributes for such a timestamp gets the error -38005. The forkchoice state of the call stays applied.
- The node does not execute such a block with the Osaka rules and does not mark it as invalid. It writes one upgrade message to standard error for each refused block.
engine_newPayloadV5 and engine_forkchoiceUpdatedV4 (and later versions) get the error -38005 also without the option. A engine_forkchoiceUpdatedV4 call does not change the head. For the option and the message, read Unsupported forks.
Payload statuses
engine_newPayload and engine_forkchoiceUpdated return a payload status with three fields: status, latestValidHash and validationError. validationError has a value only when the status is INVALID.
VALID
engine_newPayload returns VALID in these cases:
- The node executed the block on its parent and all checks passed. The checks include the state root, the receipts root, the logs bloom, the gas used and the requests hash.
- The block is already in the database as a canonical block.
- The node executed the block before and it was valid.
latestValidHash is the hash of the block.
engine_forkchoiceUpdated returns VALID when the head is a valid block that the node knows. The head can be the database head, a block in memory, or a canonical ancestor of the database head in the last 8192 blocks. For an ancestor, the node changes nothing. The Engine API specification permits the node to skip such an update.
INVALID
engine_newPayload returns INVALID in these cases:
| Cause | validationError | latestValidHash |
|---|---|---|
| A transaction in the payload is empty (zero bytes) | empty transaction | the parent rule (below) |
| A transaction cannot be decoded | invalid transaction encoding | the parent rule (below) |
extraData has more than 32 bytes | invalid payload extra data | the parent rule (below) |
| The block hash is not the hash of the payload fields | block hash mismatch | null |
| The blob versioned hashes do not agree with the transactions | blob versioned hashes mismatch | null |
| A transaction or header rule fails during execution | the name of the rule | the parent |
| The computed state root is not the root in the header | state root mismatch | the parent |
| The parent is an invalid block | links to an invalid block | the last valid ancestor |
The node checks the transactions and extraData before the block hash, as reth does. For these three causes, latestValidHash follows the rule of reth:
- The parent, when the node executed the parent and found it valid. This includes the database head and other blocks in the database.
null, when the parent is not known or is a pending block that the node did not execute.- The
latestValidHashof the parent, when the parent is invalid.
The Engine API specification gives null for an empty or bad transaction. Cinder gives the answer of reth. Both values are valid ancestors.
An invalid block stays in memory. If the consensus client sends it again, the node returns the same answer without new work. A forkchoice update to an invalid head also returns INVALID.
SYNCING
The node returns SYNCING when it cannot execute the block now:
- The parent of the payload is not known. It is not in memory, and it is not the database head.
- The parent is a canonical block below the database head, but it is older than the undo window (128 blocks). The node cannot go back that far.
- A forkchoice update names a head that the node does not know. This includes a canonical ancestor more than 8192 blocks below the database head.
- A forkchoice update selects a pending block, but the fork base is now older than the undo window or has no undo record.
A payload whose parent the node does not know gets SYNCING. If the payload is above the database head, the node keeps it: at most 256 blocks and 256 MB (#36, from v0.9.3). When the parent of a kept payload comes, the engine loop executes the payload between requests, at most 8 in one turn. The node does not keep a payload at or below the database head. It executes such a block only if the consensus client sends it again later.
After a forkchoice update with SYNCING, the node remembers the head. Between requests, it downloads the missing blocks from peers or from a backfill node, executes them and moves to that head. This needs --p2p or --backfill-rpc. Without one of these flags, the node does not get the missing blocks. For details, read P2P.
After a restart, the node can answer SYNCING for some minutes. Read SYNCING for a long time after a restart.
Forks below the database head and ACCEPTED
A block can have a parent that is a canonical block that the node already wrote to the database, below the database head and within the undo window. The answer depends on the depth of the parent:
- 1 or 2 blocks below the database head (for example a sibling of the head). The node executes the block at
engine_newPayload, over reverse layers made from the undo records, and answersVALIDorINVALID, as reth does. The database does not change. - Deeper. The node returns
ACCEPTED. It keeps the block in memory as a pending block and does not execute it yet. The node also returnsACCEPTEDfor a child of a pending block.
When a forkchoice update selects a pending block as the head, the node executes the pending blocks over reverse layers. The database does not change during this step. If one block is invalid, the answer is INVALID.
When a forkchoice update selects a valid block of such a fork, the node does not write to the database. The fork becomes the head in memory at once. Later the writer thread removes the old blocks above the fork base and writes the blocks of the fork in one transaction. Until that write, the database head stays on the old block. The JSON-RPC tag latest is the fork at once (#144). For the write, read Forks below the database head.
For the undo records and the undo window, read State database.
Errors
| Code | Message | When |
|---|---|---|
| -32700 | parse error | The body is not valid JSON. |
| -32600 | invalid request | The request is not an object or has no method. |
| -32601 | method not found | The method is not in the list above. |
| -32602 | a short reason, often the name of the bad field | A parameter is missing, has the wrong type or belongs to a later version. |
| -32603 | execution failed (N), forkchoice failed (N), out of memory | An internal error, for example a database error. N is the internal error code. An out-of-memory error in the decode of a payload also gets this error, not INVALID. |
| -38001 | Unknown payload | engine_getPayload with a payload ID that the node does not have. |
| -38002 | Invalid forkchoice state | engine_forkchoiceUpdated with a valid head, and a safe or finalized block that is not the head or one of its ancestors. The head moves to the new block. The node keeps the finalized block only if it is on the chain of the head. It does not keep the safe block. It does not build a block. |
| -38003 | Invalid payload attributes | The timestamp of the attributes is missing, or it is not after the timestamp of the head. |
| -38004 | Too large request | engine_getBlobs with more than 128 hashes. |
| -38005 | Unsupported fork | The method version does not agree with the fork. Or the timestamp of the payload or of the attributes is in no fork that Cinder implements, for example at or after --amsterdam-time. Or the method is engine_newPayloadV5, engine_forkchoiceUpdatedV4 or engine_getPayloadV6, or engine_getPayloadV1 to V3 with a payload ID that the node has. A method version that this version does not know (a fork after Amsterdam, or a version that does not exist, for example engine_getPayloadV7) gets -32601. |
An internal error is not a verdict on the block. After a failed write to the database, a call that comes before the node sees the failure gets the error -32603. Then the node prints writing blocks to the database failed and stops with the exit status 1. For more, read Troubleshooting.
Block building
Cinder builds blocks for its consensus client. It uses the transactions of its pool. For the pool, read P2P.
forkchoiceUpdated with attributes
When engine_forkchoiceUpdated has payload attributes and the forkchoice status is VALID, the node builds a block on the new head at once. The build takes tens of milliseconds on mainnet. Then the node returns the payload ID.
The payload ID is the first 8 bytes of a SHA-256 hash over the parent hash, the timestamp, prevRandao, suggestedFeeRecipient, parentBeaconBlockRoot and the withdrawals.
The node builds the block with these rules:
- Order of transactions. The node uses the order of the reth builder. Each sender's transactions come in nonce order, from the nonce of the sender's account. A gap in the nonces ends the sender's list. The sender whose next transaction pays the highest effective tip comes first.
- Fees. A transaction whose fee cap is below the base fee waits. A blob transaction whose blob fee cap is below the blob base fee also waits.
- Limits. The node skips a transaction that does not fit in the remaining gas or blob space. It then takes no more transactions from that sender.
- Block size. From Osaka, a block must stay in the size limit of 8 MiB (EIP-7934). The node adds a transaction only when the transactions in the block, this transaction, the withdrawals and 1 KiB for the header are at most 8 MiB. If a transaction does not fit, the node does not add it and takes no more transactions from its sender, but it tries the next transactions. This is the rule of reth. The pending block has no size limit, as in reth. The build has this limit from 0.9.7. Before, the build had no size limit: with a gas limit of more than about 84 000 000, transactions with much calldata could make a block that the node then refused (#352).
- Blob sidecars. The build takes the transactions of the pool without their blob sidecars, and it releases the lock of the pool after each 512 transactions. When a blob transaction fits the gas and blob limits of the block, the node gets its sidecar from the pool, before it executes the transaction, as reth does. If the pool no longer has the sidecar, or the sidecar does not have the form of the fork of the block, the block does not get the transaction. 0.9.6 and earlier copied the sidecars of all the blob transactions of the pool for each build, and held the lock of the pool during the copy. With many blob transactions in the pool, the build was slow, and a very large pool could make the build fail (#323).
- Gas limit. The gas limit moves from the gas limit of the parent toward the target of
--builder-gaslimit(default 60 000 000, as reth on mainnet). It moves by at most parent / 1024 - 1 per block. - Extra data. The extra data is the value of
--builder-extradata, cut to 32 bytes. The default value iscinder/v<version>/linux.
The node then computes the state root of the new block. It uses the same code that checks a received block.
The node keeps the last 8 built payloads. A new payload replaces the oldest one.
getPayload
engine_getPayloadV4 and V5 return the block that the payload ID names, with these fields:
executionPayload: the block.blockValue: the priority fees that go to the fee recipient.blobsBundle: the commitments, proofs and blobs of the blob transactions. Before Osaka there is one proof per blob (EIP-4844). From Osaka there are 128 cell proofs per blob (EIP-7594).executionRequests: the requests of the block (EIP-7685).shouldOverrideBuilder: alwaysfalse.
reth improves a payload until the consensus client asks for it. Cinder does a similar thing. When the built payload is 500 ms old or older, engine_getPayload builds the block again with the transactions that came since. The node keeps the block that pays more.
getBlobs
engine_getBlobsV1 and V2 return blobs from the sidecars of the blob transactions in the pool. The node selects the version by the wall clock, as reth does:
- Before Osaka, only V1 works. V1 returns one object with
blobandprooffor each hash, ornullfor a blob that the pool does not have. - From Osaka, only V2 works. V2 returns
bloband 128proofsfor each hash. If one blob is missing, V2 returnsnullfor the full request.
When a block with a blob transaction becomes part of the canonical chain, the transaction leaves the pool. The node keeps the sidecar for engine_getBlobs. The node does not offer, serve or build the transaction again. If a reorg removes the block and the new blocks do not have the transaction, it comes back to the pool with its sidecar, unchecked. engine_getBlobs serves its blobs also before the check. The validation thread then checks it on the new head. If the check fails, the transaction and its sidecar leave the pool.
What happens to a payload
engine_newPayload starts a sequence of steps: sender recovery, prewarm, execution, the state diff and the state root. While a block executes, the thread that serves the Engine API runs on a core of its own, and a coordinator thread computes most of the state root during execution. If the streamed root does not agree with the header, the node computes the root again by the old path before it returns INVALID. The node writes the block to the database later, on a writer thread. For the full sequence, read Block pipeline and Writing blocks.
The node writes a log line for each engine_newPayload and each engine_forkchoiceUpdated that gets a payload status, and for each block that it builds. For the fields of these lines, read Monitoring.