Skip to content
This repository has been archived by the owner on Aug 31, 2021. It is now read-only.
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: vulcanize/vulcanizedb
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.0.6
Choose a base ref
...
head repository: vulcanize/vulcanizedb
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.0.7
Choose a head ref

Commits on Aug 28, 2019

  1. Rename logs to full sync logs

    - Enable creating new table for logs used in event watching based on
      header sync
    rmulhol committed Aug 28, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    3693ed9 View commit details
  2. Update event transformer to take header ID

    - rather than header
    - enables executing transformers without full header lookup
    rmulhol committed Aug 28, 2019
    Copy the full SHA
    66a4e20 View commit details
  3. Write event logs to database before transforming

    - enables decoupling event extraction/persistence from transformation
    - modifies event transformer, converter, and log chunker to accept
      payload that includes internal log database ID with log data
    - remove alias for transformer pkg as shared_t
    - remove unused mock watcher repository
    rmulhol committed Aug 28, 2019
    Copy the full SHA
    cb819fa View commit details
  4. Decouple log extraction from transformer delegation

    - limit missing headers results set to 100 so that extraction doesn't
      excessively block delegation
    - wrap checked headers functions in repository struct
    - move storage repository to factory, to correspond with event
      repository path
    - remove unused files
    - reformat sql
    - remove line breaks in imports
    rmulhol committed Aug 28, 2019
    Copy the full SHA
    d496dad View commit details
  5. Copy the full SHA
    63dabbb View commit details
  6. Update comment in log chunker

    Co-Authored-By: Edvard Hübinette <edvard@hubinette.me>
    rmulhol and m0ar committed Aug 28, 2019
    Copy the full SHA
    1883a11 View commit details
  7. Remove unnecessary async from the event watcher

    - extract and delegate logs synchronously after initial goroutine fired
    rmulhol committed Aug 28, 2019
    Copy the full SHA
    d76be49 View commit details
  8. Update checked headers for new transformers

    - If a header was marked as checked before a transformer was added to
      the watcher, mark all headers since the new transformer's starting
      block number as unchecked.
    rmulhol committed Aug 28, 2019
    Copy the full SHA
    666ea1c View commit details
  9. Copy the full SHA
    222252f View commit details
  10. Make check_count a column on public.headers

    - Don't need to maintain it on public.checked_headers if we're not
      adding additional columns to that table
    rmulhol committed Aug 28, 2019
    Copy the full SHA
    5ac76ee View commit details
  11. Copy the full SHA
    b9f3b9f View commit details

Commits on Sep 10, 2019

  1. Simplify checked header repository tests

    - Use assertions instead of comments to document expectations
    - Also randomize the fake timestamp in test data
    rmulhol committed Sep 10, 2019
    Copy the full SHA
    ce91b0d View commit details
  2. Copy the full SHA
    3d6c973 View commit details
  3. Copy the full SHA
    c568fed View commit details
  4. Distinguish between missing and unchecked headers

    - Missing == not in DB
    - Unchecked == logs haven't been fetched
    rmulhol committed Sep 10, 2019
    Copy the full SHA
    13d503b View commit details

Commits on Sep 11, 2019

  1. Rename checked_logs => watched_logs

    - We're logging that a given log has been included in any fetch calls
      for checked headers, rather than that we have already checked for
      that log
    rmulhol committed Sep 11, 2019
    Copy the full SHA
    3f9b034 View commit details

Commits on Sep 13, 2019

  1. Cap random fake timestamp

    rmulhol committed Sep 13, 2019
    Copy the full SHA
    2b798e0 View commit details

Commits on Sep 19, 2019

  1. Return error when no logs/headers available

    - Replaces bool and moots question of error/bool ordering
    - Also make event watcher execution synchronous
    rmulhol committed Sep 19, 2019
    Copy the full SHA
    4fa19be View commit details
  2. Copy the full SHA
    f83e996 View commit details
  3. Put secondary processes to sleep in event watcher tests

    - Prevent extract/delegate from spinning when other side is being
      simulated
    rmulhol committed Sep 19, 2019
    Copy the full SHA
    b96a1ee View commit details

Commits on Sep 20, 2019

  1. Update Geth dep to 1.9.5

    rmulhol committed Sep 20, 2019
    Copy the full SHA
    3897b28 View commit details
  2. Merge pull request #131 from vulcanize/vdb-699-logs-table

    (VDB-699) Decouple Log extraction vs delegation to transformers
    rmulhol authored Sep 20, 2019
    Copy the full SHA
    2b151c2 View commit details
  3. Copy the full SHA
    749db40 View commit details
  4. Merge pull request #138 from vulcanize/contract-watcher-bytes32-parsing

    Parse bytes32 vals in Contract Watcher
    rmulhol authored Sep 20, 2019
    Copy the full SHA
    8bbd65e View commit details

Commits on Sep 21, 2019

  1. Correctly parse uint8 values in contract watcher

    - calling string(uint8) => insert errors on numeric columns
    rmulhol committed Sep 21, 2019
    Copy the full SHA
    3466a51 View commit details

Commits on Sep 23, 2019

  1. Merge pull request #139 from vulcanize/contract-watcher-uint8

    Correctly parse uint8 values in contract watcher
    rmulhol authored Sep 23, 2019
    Copy the full SHA
    dc30099 View commit details
  2. Do nothing on duplicate log insert

    - Prevents duplicate key constraint violation from blocking the process
      from moving forward on restart.
    - If header_id, log_idx, and tx_idx are the same, we can safely do
      nothing since it's definitely the same log - a reorg would cause the
      original header to be replaced with a new ID.
    rmulhol committed Sep 23, 2019
    Copy the full SHA
    37e2673 View commit details
  3. Merge pull request #141 from vulcanize/contract-watcher-duplicate-ins…

    …erts
    
    Do nothing on duplicate log insert in contract watcher
    rmulhol authored Sep 23, 2019
    Copy the full SHA
    a596966 View commit details
Showing with 3,038 additions and 1,277 deletions.
  1. +4 −1 cmd/composeAndExecute.go
  2. +8 −6 cmd/execute.go
  3. +18 −0 db/migrations/00007_create_full_sync_logs_table.sql
  4. +0 −19 db/migrations/00007_create_logs_table.sql
  5. +11 −17 db/migrations/00016_add_receipts_fk_to_logs.sql
  6. +24 −26 db/migrations/00018_create_watched_event_logs.sql
  7. +10 −8 db/migrations/00023_create_headers_table.sql
  8. +22 −0 db/migrations/00029_create_header_sync_logs_table.sql
  9. +12 −0 db/migrations/00030_create_watched_logs_table.sql
  10. +183 −57 db/schema.sql
  11. +17 −1 go.mod
  12. +11 −0 go.sum
  13. +3 −3 integration_test/contract_test.go
  14. +18 −22 libraries/shared/chunker/log_chunker.go
  15. +52 −41 libraries/shared/chunker/log_chunker_test.go
  16. +2 −2 libraries/shared/constants/checked_headers.go
  17. +2 −2 libraries/shared/factories/event/converter.go
  18. +2 −5 libraries/shared/factories/event/repository.go
  19. +6 −13 libraries/shared/factories/event/transformer.go
  20. +18 −38 libraries/shared/factories/event/transformer_test.go
  21. +2 −2 libraries/shared/{repository/storage_repository.go → factories/storage/repository.go}
  22. +1 −2 libraries/shared/factories/storage/transformer.go
  23. +1 −0 libraries/shared/fetcher/log_fetcher.go
  24. +85 −0 libraries/shared/logs/delegator.go
  25. +165 −0 libraries/shared/logs/delegator_test.go
  26. +154 −0 libraries/shared/logs/extractor.go
  27. +414 −0 libraries/shared/logs/extractor_test.go
  28. +35 −0 libraries/shared/logs/logs_suite_test.go
  29. +4 −6 libraries/shared/mocks/{converter.go → event_converter.go}
  30. +43 −0 libraries/shared/mocks/event_repository.go
  31. +19 −22 libraries/shared/mocks/{transformer.go → event_transformer.go}
  32. +45 −0 libraries/shared/mocks/log_delegator.go
  33. +48 −0 libraries/shared/mocks/log_extractor.go
  34. +15 −17 libraries/shared/mocks/{log_note_converter.go → log_fetcher.go}
  35. +0 −98 libraries/shared/mocks/repository.go
  36. 0 libraries/shared/mocks/{mappings.go → storage_mappings.go}
  37. +0 −69 libraries/shared/mocks/watcher_repository.go
  38. +3 −119 libraries/shared/repository/repository.go
  39. +10 −246 libraries/shared/repository/repository_test.go
  40. +27 −14 libraries/shared/test_data/generic.go
  41. +1 −3 libraries/shared/transformer/event_transformer.go
  42. +73 −100 libraries/shared/watcher/event_watcher.go
  43. +111 −170 libraries/shared/watcher/event_watcher_test.go
  44. +1 −1 pkg/contract_watcher/full/retriever/block_retriever.go
  45. +4 −4 pkg/contract_watcher/full/retriever/block_retriever_test.go
  46. +24 −6 pkg/contract_watcher/header/converter/converter.go
  47. +30 −0 pkg/contract_watcher/header/converter/converter_test.go
  48. +6 −0 pkg/contract_watcher/shared/constants/constants.go
  49. +50 −10 pkg/contract_watcher/shared/helpers/test_helpers/database.go
  50. +37 −4 pkg/contract_watcher/shared/helpers/test_helpers/mocks/entities.go
  51. +3 −3 pkg/contract_watcher/shared/repository/event_repository.go
  52. +26 −10 pkg/contract_watcher/shared/repository/event_repository_test.go
  53. +1 −1 pkg/core/blockchain.go
  54. +10 −1 pkg/core/log.go
  55. +1 −1 pkg/core/receipts.go
  56. +3 −3 pkg/datastore/postgres/postgres_test.go
  57. +11 −13 pkg/datastore/postgres/repositories/block_repository.go
  58. +17 −16 pkg/datastore/postgres/repositories/block_repository_test.go
  59. +72 −0 pkg/datastore/postgres/repositories/checked_headers_repository.go
  60. +271 −0 pkg/datastore/postgres/repositories/checked_headers_repository_test.go
  61. +69 −0 pkg/datastore/postgres/repositories/checked_logs_repository.go
  62. +115 −0 pkg/datastore/postgres/repositories/checked_logs_repository_test.go
  63. +14 −16 pkg/datastore/postgres/repositories/{logs_repository.go → full_sync_log_repository.go}
  64. +9 −10 pkg/datastore/postgres/repositories/{logs_repository_test.go → full_sync_log_repository_test.go}
  65. +17 −3 pkg/datastore/postgres/repositories/full_sync_receipt_repository.go
  66. +5 −5 pkg/datastore/postgres/repositories/full_sync_receipt_repository_test.go
  67. +146 −0 pkg/datastore/postgres/repositories/header_sync_log_repository.go
  68. +214 −0 pkg/datastore/postgres/repositories/header_sync_log_repository_test.go
  69. +4 −4 pkg/datastore/postgres/repositories/watched_events_repository_test.go
  70. +20 −3 pkg/datastore/repository.go
  71. +39 −0 pkg/fakes/checked_logs_repository.go
  72. +17 −5 pkg/fakes/data.go
  73. +2 −2 pkg/fakes/mock_blockchain.go
  74. +52 −0 pkg/fakes/mock_checked_headers_repository.go
  75. +42 −0 pkg/fakes/mock_header_sync_log_repository.go
  76. +3 −3 pkg/geth/blockchain.go
  77. +2 −2 pkg/geth/blockchain_test.go
  78. +4 −4 pkg/geth/converters/common/{log_converter.go → full_sync_log_converter.go}
  79. +3 −3 pkg/geth/converters/common/{log_converter_test.go → full_sync_log_converter_test.go}
  80. +2 −2 pkg/geth/converters/common/receipt_converter.go
  81. +2 −2 pkg/geth/converters/common/receipt_converter_test.go
  82. +11 −11 test_config/test_config.go
5 changes: 4 additions & 1 deletion cmd/composeAndExecute.go
Original file line number Diff line number Diff line change
@@ -170,7 +170,10 @@ func composeAndExecute() {
var wg syn.WaitGroup
if len(ethEventInitializers) > 0 {
ew := watcher.NewEventWatcher(&db, blockChain)
ew.AddTransformers(ethEventInitializers)
err := ew.AddTransformers(ethEventInitializers)
if err != nil {
LogWithCommand.Fatalf("failed to add event transformer initializers to watcher: %s", err.Error())
}
wg.Add(1)
go watchEthEvents(&ew, &wg)
}
14 changes: 8 additions & 6 deletions cmd/execute.go
Original file line number Diff line number Diff line change
@@ -114,7 +114,10 @@ func execute() {
var wg syn.WaitGroup
if len(ethEventInitializers) > 0 {
ew := watcher.NewEventWatcher(&db, blockChain)
ew.AddTransformers(ethEventInitializers)
err = ew.AddTransformers(ethEventInitializers)
if err != nil {
LogWithCommand.Fatalf("failed to add event transformer initializers to watcher: %s", err.Error())
}
wg.Add(1)
go watchEthEvents(&ew, &wg)
}
@@ -155,12 +158,11 @@ func watchEthEvents(w *watcher.EventWatcher, wg *syn.WaitGroup) {
if recheckHeadersArg {
recheck = constants.HeaderRecheck
} else {
recheck = constants.HeaderMissing
recheck = constants.HeaderUnchecked
}
ticker := time.NewTicker(pollingInterval)
defer ticker.Stop()
for range ticker.C {
w.Execute(recheck)
err := w.Execute(recheck)
if err != nil {
LogWithCommand.Fatalf("error executing event watcher: %s", err.Error())
}
}

18 changes: 18 additions & 0 deletions db/migrations/00007_create_full_sync_logs_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-- +goose Up
CREATE TABLE full_sync_logs
(
id SERIAL PRIMARY KEY,
block_number BIGINT,
address VARCHAR(66),
tx_hash VARCHAR(66),
index BIGINT,
topic0 VARCHAR(66),
topic1 VARCHAR(66),
topic2 VARCHAR(66),
topic3 VARCHAR(66),
data TEXT
);


-- +goose Down
DROP TABLE full_sync_logs;
19 changes: 0 additions & 19 deletions db/migrations/00007_create_logs_table.sql

This file was deleted.

28 changes: 11 additions & 17 deletions db/migrations/00016_add_receipts_fk_to_logs.sql
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
-- +goose Up
ALTER TABLE logs
DROP CONSTRAINT log_uc;
ALTER TABLE full_sync_logs
ADD COLUMN receipt_id INT;

ALTER TABLE logs
ADD COLUMN receipt_id INT;

ALTER TABLE logs
ADD CONSTRAINT receipts_fk
FOREIGN KEY (receipt_id)
REFERENCES full_sync_receipts (id)
ON DELETE CASCADE;
ALTER TABLE full_sync_logs
ADD CONSTRAINT receipts_fk
FOREIGN KEY (receipt_id)
REFERENCES full_sync_receipts (id)
ON DELETE CASCADE;


-- +goose Down
ALTER TABLE logs
DROP CONSTRAINT receipts_fk;

ALTER TABLE logs
DROP COLUMN receipt_id;
ALTER TABLE full_sync_logs
DROP CONSTRAINT receipts_fk;

ALTER TABLE logs
ADD CONSTRAINT log_uc UNIQUE (block_number, index);
ALTER TABLE full_sync_logs
DROP COLUMN receipt_id;
50 changes: 24 additions & 26 deletions db/migrations/00018_create_watched_event_logs.sql
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
-- +goose Up
CREATE VIEW block_stats AS
SELECT
max(block_number) AS max_block,
min(block_number) AS min_block
FROM logs;
SELECT max(block_number) AS max_block,
min(block_number) AS min_block
FROM full_sync_logs;

CREATE VIEW watched_event_logs AS
SELECT
log_filters.name,
logs.id,
block_number,
logs.address,
tx_hash,
index,
logs.topic0,
logs.topic1,
logs.topic2,
logs.topic3,
data,
receipt_id
FROM log_filters
CROSS JOIN block_stats
JOIN logs ON logs.address = log_filters.address
AND logs.block_number >= coalesce(log_filters.from_block, block_stats.min_block)
AND logs.block_number <= coalesce(log_filters.to_block, block_stats.max_block)
WHERE (log_filters.topic0 = logs.topic0 OR log_filters.topic0 ISNULL)
AND (log_filters.topic1 = logs.topic1 OR log_filters.topic1 ISNULL)
AND (log_filters.topic2 = logs.topic2 OR log_filters.topic2 ISNULL)
AND (log_filters.topic3 = logs.topic3 OR log_filters.topic3 ISNULL);
SELECT log_filters.name,
full_sync_logs.id,
block_number,
full_sync_logs.address,
tx_hash,
index,
full_sync_logs.topic0,
full_sync_logs.topic1,
full_sync_logs.topic2,
full_sync_logs.topic3,
data,
receipt_id
FROM log_filters
CROSS JOIN block_stats
JOIN full_sync_logs ON full_sync_logs.address = log_filters.address
AND full_sync_logs.block_number >= coalesce(log_filters.from_block, block_stats.min_block)
AND full_sync_logs.block_number <= coalesce(log_filters.to_block, block_stats.max_block)
WHERE (log_filters.topic0 = full_sync_logs.topic0 OR log_filters.topic0 ISNULL)
AND (log_filters.topic1 = full_sync_logs.topic1 OR log_filters.topic1 ISNULL)
AND (log_filters.topic2 = full_sync_logs.topic2 OR log_filters.topic2 ISNULL)
AND (log_filters.topic3 = full_sync_logs.topic3 OR log_filters.topic3 ISNULL);

-- +goose Down
DROP VIEW watched_event_logs;
18 changes: 10 additions & 8 deletions db/migrations/00023_create_headers_table.sql
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
-- +goose Up
CREATE TABLE public.headers (
id SERIAL PRIMARY KEY,
hash VARCHAR(66),
block_number BIGINT,
raw JSONB,
block_timestamp NUMERIC,
eth_node_id INTEGER NOT NULL REFERENCES eth_nodes (id) ON DELETE CASCADE,
eth_node_fingerprint VARCHAR(128)
CREATE TABLE public.headers
(
id SERIAL PRIMARY KEY,
hash VARCHAR(66),
block_number BIGINT,
raw JSONB,
block_timestamp NUMERIC,
check_count INTEGER NOT NULL DEFAULT 0,
eth_node_id INTEGER NOT NULL REFERENCES eth_nodes (id) ON DELETE CASCADE,
eth_node_fingerprint VARCHAR(128)
);

-- Index is removed when table is
22 changes: 22 additions & 0 deletions db/migrations/00029_create_header_sync_logs_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-- +goose Up
-- SQL in this section is executed when the migration is applied.
CREATE TABLE header_sync_logs
(
id SERIAL PRIMARY KEY,
header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE,
address INTEGER NOT NULL REFERENCES addresses (id) ON DELETE CASCADE,
topics BYTEA[],
data BYTEA,
block_number BIGINT,
block_hash VARCHAR(66),
tx_hash VARCHAR(66),
tx_index INTEGER,
log_index INTEGER,
raw JSONB,
transformed BOOL NOT NULL DEFAULT FALSE,
UNIQUE (header_id, tx_index, log_index)
);

-- +goose Down
-- SQL in this section is executed when the migration is rolled back.
DROP TABLE header_sync_logs;
12 changes: 12 additions & 0 deletions db/migrations/00030_create_watched_logs_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- +goose Up
-- SQL in this section is executed when the migration is applied.
CREATE TABLE public.watched_logs
(
id SERIAL PRIMARY KEY,
contract_address VARCHAR(42),
topic_zero VARCHAR(66)
);

-- +goose Down
-- SQL in this section is executed when the migration is rolled back.
DROP TABLE public.watched_logs;
Loading