Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
hivemind
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hive
hivemind
Commits
dfc8c67b
Commit
dfc8c67b
authored
7 years ago
by
Tim
Browse files
Options
Downloads
Patches
Plain Diff
core indexer to use block hash FK, will explode if forks
parent
1d71d3d2
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
hive/db/schema.py
+6
-4
6 additions, 4 deletions
hive/db/schema.py
hive/indexer/core.py
+5
-6
5 additions, 6 deletions
hive/indexer/core.py
with
11 additions
and
10 deletions
hive/db/schema.py
+
6
−
4
View file @
dfc8c67b
...
...
@@ -12,11 +12,13 @@ metadata = sa.MetaData()
hive_blocks
=
sa
.
Table
(
'
hive_blocks
'
,
metadata
,
sa
.
Column
(
'
num
'
,
sa
.
Integer
,
primary_key
=
True
,
autoincrement
=
False
),
sa
.
Column
(
'
prev
'
,
sa
.
Integer
),
sa
.
Column
(
'
hash
'
,
CHAR
(
40
,
ascii
=
True
),
nullable
=
False
),
sa
.
Column
(
'
prev
'
,
CHAR
(
40
,
ascii
=
True
)),
sa
.
Column
(
'
txs
'
,
SMALLINT
(
unsigned
=
True
),
server_default
=
'
0
'
,
nullable
=
False
),
sa
.
Column
(
'
created_at
'
,
sa
.
DateTime
,
nullable
=
False
),
sa
.
UniqueConstraint
(
'
prev
'
,
name
=
'
hive_blocks_ux1
'
),
sa
.
ForeignKeyConstraint
([
'
prev
'
],
[
'
hive_blocks.num
'
],
name
=
'
hive_blocks_fk1
'
),
sa
.
UniqueConstraint
(
'
hash
'
,
name
=
'
hive_blocks_ux1
'
),
sa
.
UniqueConstraint
(
'
prev
'
,
name
=
'
hive_blocks_ux2
'
),
sa
.
ForeignKeyConstraint
([
'
prev
'
],
[
'
hive_blocks.hash
'
],
name
=
'
hive_blocks_fk1
'
),
mysql_engine
=
'
InnoDB
'
,
mysql_default_charset
=
'
utf8mb4
'
)
...
...
@@ -203,7 +205,7 @@ def setup(connection_url=_url):
conn
=
engine
.
connect
()
# Insert hive_blocks data
insert
=
hive_blocks
.
insert
().
values
(
num
=
0
,
prev
=
None
,
created_at
=
'
1970-01-01T00:00:00
'
)
insert
=
hive_blocks
.
insert
().
values
(
num
=
0
,
hash
=
'
0000000000000000000000000000000000000000
'
,
prev
=
None
,
created_at
=
'
1970-01-01T00:00:00
'
)
conn
.
execute
(
insert
)
# Insert hive_accounts data
...
...
This diff is collapsed.
Click to expand it.
hive/indexer/core.py
+
5
−
6
View file @
dfc8c67b
...
...
@@ -311,14 +311,13 @@ def is_community(name: str) -> bool:
# -----------
def
process_block
(
block
):
date
=
parse_time
(
block
[
'
timestamp
'
])
block_num
=
int
(
block
[
'
previous
'
][:
8
],
base
=
16
)
+
1
block_id
=
block
[
'
block_id
'
]
prev
=
block
[
'
previous
'
]
block_num
=
int
(
block_id
[:
8
],
base
=
16
)
txs
=
block
[
'
transactions
'
]
# NOTE: currently `prev` tracks the previous block number and this is enforced with a FK constraint.
# soon we will have access to prev block hash and current hash in the API return value, we should use this instead.
# the FK constraint will then fail if we somehow end up on the wrong side in a fork reorg.
query
(
"
INSERT INTO hive_blocks (num, prev, txs, created_at)
"
"
VALUES (
'
%d
'
,
'
%d
'
,
'
%d
'
,
'
%s
'
)
"
%
(
block_num
,
block_num
-
1
,
len
(
txs
),
date
))
query
(
"
INSERT INTO hive_blocks (num, hash, prev, txs, created_at)
"
"
VALUES (%d,
'
%s
'
,
'
%s
'
, %d,
'
%s
'
)
"
%
(
block_num
,
block_id
,
prev
,
len
(
txs
),
date
))
accounts
=
set
()
comments
=
[]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment