Skip to content

Commit

Permalink
Fix transactionsRoot and sha3Uncles in eth_getBlockByNumber. (#141
Browse files Browse the repository at this point in the history
)
  • Loading branch information
spilin authored Dec 20, 2021
1 parent 7d5bc8d commit 751e58a
Show file tree
Hide file tree
Showing 15 changed files with 350 additions and 35 deletions.
4 changes: 2 additions & 2 deletions .docker/docker-entrypoint-initdb.d/init.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ CREATE TYPE block_result AS (
"size" int4,
"gasLimit" int8,
"gasUsed" int8,
"mixHash" hash,
"mixHash" hash,
"timestamp" int4
);
DROP TYPE IF EXISTS filter_result CASCADE;
Expand Down Expand Up @@ -221,7 +221,7 @@ BEGIN
hash, -- hash
parent_hash, -- parentHash
repeat('\000', 8)::bytea, -- nonce
repeat('\000', 32)::bytea, -- sha3Uncles
'\x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', -- sha3Uncles keccak256(rlp.encode([]))
repeat('\000', 256)::bytea, -- logsBloom
transactions_root, -- transactionsRoot
state_root, -- stateRoot
Expand Down
15 changes: 15 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## 2021-12-14

- Run `node lib/data_migrations/2021-12-14-empty-blocks.js` to reindex all historical empty blocks.
In addition, reload the following stored procedures:

- `etc/schema/functions/eth_getBlockByNumber.sql`

or

```bash
$ cd migrations
$ goose postgres "user=<USERNAME> password=<PASSWORD> dbname=aurora sslmode=disable" up
```

## 2021-12-08

A new column `from` was added into the `event` table. Check out this PR [#120](https://github.com/aurora-is-near/aurora-relayer/pull/120) for more info.
Expand Down
2 changes: 1 addition & 1 deletion etc/schema/functions/eth_getBlockByNumber.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ BEGIN
hash, -- hash
parent_hash, -- parentHash
repeat('\000', 8)::bytea, -- nonce
repeat('\000', 32)::bytea, -- sha3Uncles
'\x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', -- sha3Uncles keccak256(rlp.encode([]))
repeat('\000', 256)::bytea, -- logsBloom
transactions_root, -- transactionsRoot
state_root, -- stateRoot
Expand Down
7 changes: 7 additions & 0 deletions lib/data_migrations/2021-12-14-empty-blocks.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { ConnectEnv } from '@aurora-is-near/engine';
declare global {
namespace NodeJS {
interface ProcessEnv extends ConnectEnv {
}
}
}
77 changes: 77 additions & 0 deletions lib/data_migrations/2021-12-14-empty-blocks.js

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

11 changes: 7 additions & 4 deletions lib/indexer_worker.js

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

1 change: 1 addition & 0 deletions lib/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ export declare type EmptyBlock = {
};
export declare function computeBlockHash(blockHeight: number, accountId: string, chainId: number): Buffer;
export declare function generateEmptyBlock(blockHeight: number, accountId: string, chainId: number): EmptyBlock;
export declare function emptyTransactionsRoot(): Buffer;
7 changes: 6 additions & 1 deletion lib/utils.js

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
-- +goose Up
-- +goose StatementBegin
CREATE OR REPLACE FUNCTION eth_getBlockByNumber(block_id blockno) RETURNS block_result AS $$
DECLARE
result block_result;
BEGIN
SELECT
id, -- number
hash, -- hash
parent_hash, -- parentHash
repeat('\000', 8)::bytea, -- nonce
'\x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', -- sha3Uncles keccak256(rlp.encode([]))
repeat('\000', 256)::bytea, -- logsBloom
transactions_root, -- transactionsRoot
state_root, -- stateRoot
receipts_root, -- receiptsRoot
repeat('\000', 20)::bytea, -- miner
0, -- difficulty
0, -- totalDifficulty
''::bytea, -- extraData
size, -- size
gas_limit, -- gasLimit
gas_used, -- gasUsed
repeat('\000', 32)::hash, -- mixHash
COALESCE(EXTRACT(EPOCH FROM timestamp), 0)::int4 -- timestamp
FROM block
WHERE id = block_id
LIMIT 1
INTO STRICT result;
RETURN result;
END;
$$ LANGUAGE plpgsql VOLATILE PARALLEL UNSAFE;
-- +goose StatementEnd

-- +goose Down
-- +goose StatementBegin
CREATE OR REPLACE FUNCTION eth_getBlockByNumber(block_id blockno) RETURNS block_result AS $$
DECLARE
result block_result;
BEGIN
SELECT
id, -- number
hash, -- hash
parent_hash, -- parentHash
repeat('\000', 8)::bytea, -- nonce
repeat('\000', 32)::bytea, -- sha3Uncles
repeat('\000', 256)::bytea, -- logsBloom
transactions_root, -- transactionsRoot
state_root, -- stateRoot
receipts_root, -- receiptsRoot
repeat('\000', 20)::bytea, -- miner
0, -- difficulty
0, -- totalDifficulty
''::bytea, -- extraData
size, -- size
gas_limit, -- gasLimit
gas_used, -- gasUsed
repeat('\000', 32)::hash, -- mixHash
COALESCE(EXTRACT(EPOCH FROM timestamp), 0)::int4 -- timestamp
FROM block
WHERE id = block_id
LIMIT 1
INTO STRICT result;
RETURN result;
END;
$$ LANGUAGE plpgsql VOLATILE PARALLEL UNSAFE;
-- +goose StatementEnd
30 changes: 9 additions & 21 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"node-worker-threads-pool": "^1.5.1",
"pg": "^8.7.1",
"pg-format": "^1.0.4",
"rlp": "^2.2.6",
"rlp": "^2.2.7",
"sql-bricks-postgres": "^0.5.0",
"ts-jest": "^27.0.3",
"ws": "^8.2.3"
Expand Down
Loading

0 comments on commit 751e58a

Please sign in to comment.