Skip to content

Commit

Permalink
Handle transaction re-pricing and multiple inclusion (#36)
Browse files Browse the repository at this point in the history
* EL mock

* WIP mock server

* wait for mined block

* can mine blocks

* advance head on mine

* Handle multiple inclusions

* update tests

* fix tests

* lint

* docs

* remove fee estimator
  • Loading branch information
dapplion authored Jan 2, 2024
1 parent a31d663 commit 92af4b3
Show file tree
Hide file tree
Showing 27 changed files with 1,741 additions and 637 deletions.

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

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

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

24 changes: 20 additions & 4 deletions migrations/20231223063356_create_data_intent_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,25 @@
-- - User may submit the same data twice
-- - Economically bounded, only accepts data intents that the user can afford
-- - Never pruned, data intents remain in the DB forever after finalization
--
-- # Queries
-- * For packing retrieve intents available for inclusion (non included + underpriced)
-- > Select all rows WHERE inclusion_finalized == false
-- * Intent explorer, return intent details by id
--
-- # Pruning
-- Never prunes
--
-- # Mutation
-- Set `inclusion_finalized = true` after finalizing inclusion. This value is an optimization,
-- and can be updated at any latter point. An consumer should do a consistency check on startup
-- to potentially set inclusion_finalized to true if: there's a an inclusion, for a known tx, in
-- a block with number < anchor block.
--
CREATE TABLE data_intents (
id BINARY(16) PRIMARY KEY, -- UUID as binary
-- sender address
eth_address BINARY(20),
eth_address BINARY(20) NOT NULL,
-- binary data to publish, MEDIUMBLOB = binary large object with max length of 2^24-1 bytes (16MB)
data MEDIUMBLOB NOT NULL,
-- byte length of data, max possible size is 131,072 < INT::MAX = 2,147,483,647
Expand All @@ -16,12 +31,13 @@ CREATE TABLE data_intents (
max_blob_gas_price BIGINT UNSIGNED NOT NULL,
-- Optional ECDSA signature over data_hash, serialized
data_hash_signature BINARY(65) DEFAULT NULL,
-- Transaction hash of the included
inclusion_tx_hash BINARY(32) DEFAULT NULL,
-- Inclusion finalized
inclusion_finalized BOOL DEFAULT false,
-- Timestamp with milisecond level precision, automatically populated
updated_at TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
-- Index created_at to query recently added intents efficiently. The query:
-- `EXPLAIN ANALYZE SELECT * FROM data_intents WHERE updated_at > '2024-01-01 00:00:00';`
-- against PlanetScale consumes 0 row read credits if there are no matches.
INDEX(updated_at)
INDEX(updated_at),
INDEX(inclusion_finalized)
);
33 changes: 33 additions & 0 deletions migrations/20240101133133_create_intent_inclusion_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
-- # Queries
-- * List of intent IDs that can be included in a new bundle (no inclusion + underpriced inclusion)
-- > Query all rows with nonce > finalized nonce for sender address
-- * For a specific historic intent ID, retrieve which transaction and block is included into efficiently
-- > Query rows WHERE id = ? and pick the most recent or canonical
-- * Prune inclusions for dropped transactions
-- > Remove rows WHERE tx_hash = ?
--
-- # Pruning
-- Prunes non canonical re-priced transactions
--
-- # Mutation
-- None
--
CREATE TABLE intent_inclusions (
-- data intent UUID as binary
id BINARY(16) NOT NULL,
-- Transaction hash that includes this set of IDs
tx_hash BINARY(32) NOT NULL,
-- Tx from
sender_address BINARY(20) NOT NULL,
-- Tx nonce from sender
nonce INT NOT NULL,
-- Timestamp with milisecond level precision, automatically populated
updated_at TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),

PRIMARY KEY(id, tx_hash),
-- Allow to query inclusions by data intent ID or transaction hash
INDEX(id),
INDEX(tx_hash),
INDEX(sender_address),
INDEX(nonce)
);
Loading

0 comments on commit 92af4b3

Please sign in to comment.