Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cellframe-sdk
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Merge requests
20
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
cellframe
cellframe-sdk
Commits
a2ec1198
Commit
a2ec1198
authored
3 years ago
by
Roman Khlopkov
🔜
Browse files
Options
Downloads
Patches
Plain Diff
[+] Block files ops
parent
45137261
No related branches found
No related tags found
2 merge requests
!494
Add hotfix for ticket 5461
,
!489
features-5240
Pipeline
#11782
passed with stage
Stage: analyze
in 11 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
modules/type/blocks/dap_chain_block_cache.c
+1
-0
1 addition, 0 deletions
modules/type/blocks/dap_chain_block_cache.c
modules/type/blocks/dap_chain_cs_blocks.c
+43
-13
43 additions, 13 deletions
modules/type/blocks/dap_chain_cs_blocks.c
with
44 additions
and
13 deletions
modules/type/blocks/dap_chain_block_cache.c
+
1
−
0
View file @
a2ec1198
...
...
@@ -93,6 +93,7 @@ int dap_chain_block_cache_update(dap_chain_block_cache_t * a_block_cache)
assert
(
a_block_cache
);
assert
(
a_block_cache
->
block
);
dap_hash_fast
(
a_block_cache
->
block
,
a_block_cache
->
block_size
,
&
a_block_cache
->
block_hash
);
a_block_cache
->
block_hash_str
=
dap_hash_fast_to_str_new
(
&
a_block_cache
->
block_hash
);
if
(
a_block_cache
->
meta
)
DAP_DELETE
(
a_block_cache
->
meta
);
if
(
a_block_cache
->
datum
)
...
...
This diff is collapsed.
Click to expand it.
modules/type/blocks/dap_chain_cs_blocks.c
+
43
−
13
View file @
a2ec1198
...
...
@@ -672,7 +672,9 @@ static int s_add_atom_to_ledger(dap_chain_cs_blocks_t * a_blocks, dap_ledger_t
static
int
s_add_atom_to_blocks
(
dap_chain_cs_blocks_t
*
a_blocks
,
dap_ledger_t
*
a_ledger
,
dap_chain_block_cache_t
*
a_block_cache
)
{
pthread_rwlock_rdlock
(
&
PVT
(
a_blocks
)
->
rwlock
);
int
res
=
a_blocks
->
callback_block_verify
(
a_blocks
,
a_block_cache
->
block
,
a_block_cache
->
block_size
);
int
res
=
a_blocks
->
callback_block_verify
?
a_blocks
->
callback_block_verify
(
a_blocks
,
a_block_cache
->
block
,
a_block_cache
->
block_size
)
:
0
;
if
(
res
==
0
||
memcmp
(
&
a_block_cache
->
block_hash
,
&
PVT
(
a_blocks
)
->
genesis_block_hash
,
sizeof
(
a_block_cache
->
block_hash
)
)
==
0
)
{
log_it
(
L_DEBUG
,
"Block %s checked, add it to ledger"
,
a_block_cache
->
block_hash_str
);
pthread_rwlock_unlock
(
&
PVT
(
a_blocks
)
->
rwlock
);
...
...
@@ -865,19 +867,19 @@ static dap_chain_atom_verify_res_t s_callback_atom_verify(dap_chain_t * a_chain,
if
(
res
==
ATOM_ACCEPT
){
// genesis or seed mode
if
(
l_is_genesis
){
if
(
s_seed_mode
&&
!
l_blocks_pvt
->
blocks
){
log_it
(
L_NOTICE
,
"Accepting new genesis block"
);
return
ATOM_ACCEPT
;
}
else
if
(
s_seed_mode
){
if
(
l_is_genesis
)
{
if
(
!
l_blocks_pvt
->
blocks
)
{
if
(
s_seed_mode
)
log_it
(
L_NOTICE
,
"Accepting new genesis block"
);
else
log_it
(
L_NOTICE
,
"Accepting static genesis block"
);
}
else
{
log_it
(
L_WARNING
,
"Cant accept genesis block: already present data in blockchain"
);
re
turn
ATOM_REJECT
;
re
s
=
ATOM_REJECT
;
}
}
else
{
if
(
PVT
(
l_blocks
)
->
block_cache_last
)
if
(
!
dap_hash_fast_compare
(
&
PVT
(
l_blocks
)
->
block_cache_last
->
block_hash
,
&
l_block_prev_hash
)
)
res
=
ATOM_MOVE_TO_THRESHOLD
;
}
}
else
if
(
!
PVT
(
l_blocks
)
->
block_cache_last
||
!
dap_hash_fast_compare
(
&
PVT
(
l_blocks
)
->
block_cache_last
->
block_hash
,
&
l_block_prev_hash
))
res
=
ATOM_MOVE_TO_THRESHOLD
;
}
...
...
@@ -1123,8 +1125,36 @@ static int s_new_block_complete(dap_chain_cs_blocks_t *a_blocks)
}
dap_chain_atom_verify_res_t
l_res
=
s_callback_atom_add
(
a_blocks
->
chain
,
a_blocks
->
block_new
,
a_blocks
->
block_new_size
);
DAP_DEL_Z
(
a_blocks
->
block_new
);
if
(
l_res
==
ATOM_ACCEPT
)
if
(
l_res
==
ATOM_ACCEPT
)
{
if
(
dap_chain_atom_save
(
a_blocks
->
chain
,
(
uint8_t
*
)
a_blocks
->
block_new
,
a_blocks
->
block_new_size
,
a_blocks
->
chain
->
cells
->
id
)
<
0
)
{
log_it
(
L_ERROR
,
"Can't add new event to the file"
);
}
/* TODO add all atoms from treshold
dap_chain_net_t *l_net = dap_chain_net_by_id(a_chain->net_id);
dap_chain_t *l_cur_chain;
bool l_processed;
do {
l_processed = false;
DL_FOREACH(l_net->pub.chains, l_cur_chain) {
if (l_cur_chain->callback_atom_add_from_treshold) {
dap_chain_atom_ptr_t l_atom_treshold;
do {
size_t l_atom_treshold_size;
// add in ledger
l_atom_treshold = l_cur_chain->callback_atom_add_from_treshold(l_cur_chain, &l_atom_treshold_size);
// add into file
if (l_atom_treshold) {
int l_res = dap_chain_atom_save(l_cur_chain, l_atom_treshold, l_atom_treshold_size, l_cur_chain->cells->id);
if (l_res < 0) {
log_it(L_ERROR, "Can't save event %p from treshold", l_atom_treshold);
}
}
} while (l_atom_treshold);
}
}
} while (l_processed); */
return
0
;
}
return
-
2
;
}
...
...
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