Skip to content

Commit

Permalink
Make blocks.sha3uncles column nullable (#709)
Browse files Browse the repository at this point in the history
* Make sha3uncles nullable

Some chains, such as Celo, do not contain sha3Uncles in their
block headers.  Lets make this field nullable in postgres and
sqlite to allow use of Ponder on these chains.

* changeset
  • Loading branch information
d-mooers authored Mar 14, 2024
1 parent 9b0824b commit eebb173
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/dull-laws-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ponder/core": patch
---

Made block.sha3Uncles column nullable
4 changes: 2 additions & 2 deletions packages/core/src/sync-store/postgres/encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type BlocksTable = {
number: bigint;
parentHash: Hash;
receiptsRoot: Hex;
sha3Uncles: Hash;
sha3Uncles: Hash | null;
size: bigint;
stateRoot: Hash;
timestamp: bigint;
Expand Down Expand Up @@ -52,7 +52,7 @@ export function rpcToPostgresBlock(
number: BigInt(block.number!),
parentHash: block.parentHash,
receiptsRoot: block.receiptsRoot,
sha3Uncles: block.sha3Uncles,
sha3Uncles: block.sha3Uncles ?? null,
size: BigInt(block.size),
stateRoot: block.stateRoot,
timestamp: BigInt(block.timestamp),
Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/sync-store/postgres/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,14 @@ const migrations: Record<string, Migration> = {
.execute();
},
},
"2024_03_13_0_nullable_block_columns_sha3uncles": {
async up(db: Kysely<any>) {
await db.schema
.alterTable("blocks")
.alterColumn("sha3Uncles", (col) => col.dropNotNull())
.execute();
},
},
};

class StaticMigrationProvider implements MigrationProvider {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/sync-store/sqlite/encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type BlocksTable = {
number: BigIntText;
parentHash: Hash;
receiptsRoot: Hex;
sha3Uncles: Hash;
sha3Uncles: Hash | null;
size: BigIntText;
stateRoot: Hash;
timestamp: BigIntText;
Expand Down Expand Up @@ -57,7 +57,7 @@ export function rpcToSqliteBlock(
number: encodeAsText(block.number!),
parentHash: block.parentHash,
receiptsRoot: block.receiptsRoot,
sha3Uncles: block.sha3Uncles,
sha3Uncles: block.sha3Uncles ?? null,
size: encodeAsText(block.size),
stateRoot: block.stateRoot,
timestamp: encodeAsText(block.timestamp),
Expand Down
19 changes: 19 additions & 0 deletions packages/core/src/sync-store/sqlite/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,25 @@ const migrations: Record<string, Migration> = {
.execute();
},
},
"2024_03_13_0_nullable_block_columns_sha3uncles": {
async up(db: Kysely<any>) {
await db.schema
.alterTable("blocks")
.addColumn("sha3Uncles_temp_null", "varchar(66)")
.execute();
await db
.updateTable("blocks")
.set((eb: any) => ({
sha3Uncles_temp_null: eb.selectFrom("blocks").select("sha3Uncles"),
}))
.execute();
await db.schema.alterTable("blocks").dropColumn("sha3Uncles").execute();
await db.schema
.alterTable("blocks")
.renameColumn("sha3Uncles_temp_null", "sha3Uncles")
.execute();
},
},
};

class StaticMigrationProvider implements MigrationProvider {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/types/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export type Block = {
/** Root of the this block’s receipts trie */
receiptsRoot: Hex;
/** SHA3 of the uncles data in this block */
sha3Uncles: Hash;
sha3Uncles: Hash | null;
/** Size of this block in bytes */
size: bigint;
/** Root of this block’s final state trie */
Expand Down

0 comments on commit eebb173

Please sign in to comment.