Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
duniter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
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
nodes
typescript
duniter
Commits
e7dbaebe
Commit
e7dbaebe
authored
1 year ago
by
Benoit Lavenier
Browse files
Options
Downloads
Patches
Plain Diff
[fix] Delete or update 'indexOfComplexeConditionForPubkeys' when removing a block
parent
5ec7a750
No related branches found
No related tags found
1 merge request
!1420
[fix] Optimize access to sources by pubkey, using specific index
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/lib/dal/indexDAL/leveldb/LevelDBSindex.ts
+37
-13
37 additions, 13 deletions
app/lib/dal/indexDAL/leveldb/LevelDBSindex.ts
with
37 additions
and
13 deletions
app/lib/dal/indexDAL/leveldb/LevelDBSindex.ts
+
37
−
13
View file @
e7dbaebe
...
...
@@ -129,9 +129,9 @@ export class LevelDBSindex extends LevelDBTable<SindexEntry>
pos
:
number
;
}[]
>
{
const
forConditions
=
await
this
.
getForConditions
(
`SIG(
${
pubkey
}
)`
);
const
for
Pubkey
s
=
await
this
.
getForComplexeConditionPubkey
(
pubkey
);
const
reduced
=
Indexer
.
DUP_HELPERS
.
reduceBy
(
forConditions
.
concat
(
for
Pubkey
s
),
[
const
for
Simple
Conditions
=
await
this
.
getForConditions
(
`SIG(
${
pubkey
}
)`
);
const
for
ComplexCondition
s
=
await
this
.
getForComplexeConditionPubkey
(
pubkey
);
const
reduced
=
Indexer
.
DUP_HELPERS
.
reduceBy
(
for
Simple
Conditions
.
concat
(
for
ComplexCondition
s
),
[
"
identifier
"
,
"
pos
"
,
]);
...
...
@@ -329,24 +329,25 @@ export class LevelDBSindex extends LevelDBTable<SindexEntry>
}
private
async
trimConditions
(
condition
:
string
,
id
:
string
)
{
// Get all the
account's TX
sources
// Get all the
condition's
sources
const
existing
=
(
await
this
.
indexForConditions
.
getOrNull
(
condition
))
||
[];
// Prune the source from the
account
// Prune the source from the
condition
const
trimmed
=
arrayPruneAllCopy
(
existing
,
id
);
if
(
trimmed
.
length
)
{
// If some sources are left for this "
account
", persist what remains
// If some sources are left for this "
condition
", persist what remains
await
this
.
indexForConditions
.
put
(
condition
,
trimmed
);
}
else
{
// Otherwise just delete the "account"
await
this
.
indexForConditions
.
del
(
condition
);
}
// If complex conditions
if
(
this
.
isComplexCondition
(
condition
))
{
const
pubkeys
=
this
.
getDistinctPubkeysFromCondition
(
condition
);
await
this
.
trimComplexeConditionPubkeys
(
pubkeys
,
id
);
}
}
/**
* Duplicate with trimConditions?!
* @param writtenOn
* @param id
*/
private
async
trimWrittenOn
(
writtenOn
:
number
,
id
:
string
)
{
const
k
=
LevelDBSindex
.
trimWrittenOnKey
(
writtenOn
);
const
existing
=
await
this
.
getWrittenOnSourceIds
(
writtenOn
);
...
...
@@ -369,6 +370,27 @@ export class LevelDBSindex extends LevelDBTable<SindexEntry>
}
}
private
async
trimComplexeConditionPubkeys
(
pubkeys
:
string
[],
id
:
string
)
{
if
(
!
pubkeys
||
!
pubkeys
.
length
)
return
;
for
(
const
p
of
pubkeys
)
{
await
this
.
trimComplexeConditionPubkey
(
p
,
id
);
}
}
private
async
trimComplexeConditionPubkey
(
pubkey
:
string
,
id
:
string
)
{
// Get all the condition's sources
const
existing
=
(
await
this
.
indexOfComplexeConditionForPubkeys
.
getOrNull
(
pubkey
))
||
[];
// Prune the source from the condition
const
trimmed
=
arrayPruneAllCopy
(
existing
,
id
);
if
(
trimmed
.
length
)
{
// If some sources are left for this "condition", persist what remains
await
this
.
indexOfComplexeConditionForPubkeys
.
put
(
pubkey
,
trimmed
);
}
else
{
// Otherwise just delete the "account"
await
this
.
indexOfComplexeConditionForPubkeys
.
del
(
pubkey
);
}
}
private
async
getWrittenOnSourceIds
(
writtenOn
:
number
)
{
const
indexForTrimmingId
=
LevelDBSindex
.
trimWrittenOnKey
(
writtenOn
);
return
(
await
this
.
indexForTrimming
.
getOrNull
(
indexForTrimmingId
))
||
[];
...
...
@@ -432,8 +454,7 @@ export class LevelDBSindex extends LevelDBTable<SindexEntry>
arrCN
.
push
(
r
);
// If complex condition
if
(
!
CommonConstants
.
TRANSACTION
.
OUTPUT_CONDITION_SIG_PUBKEY_UNIQUE
.
test
(
r
.
conditions
))
{
// Fill complex condition by pubkey
if
(
this
.
isComplexCondition
(
r
.
conditions
))
{
const
pubkeys
=
this
.
getDistinctPubkeysFromCondition
(
r
.
conditions
);
pubkeys
.
forEach
((
pub
)
=>
{
let
arrPub
=
byPubkeys
[
pub
];
...
...
@@ -486,6 +507,9 @@ export class LevelDBSindex extends LevelDBTable<SindexEntry>
}
}
private
isComplexCondition
(
condition
:
string
):
boolean
{
return
condition
&&
!
CommonConstants
.
TRANSACTION
.
OUTPUT_CONDITION_SIG_PUBKEY_UNIQUE
.
test
(
condition
)
||
false
;
}
/**
* Get all pubkeys used by an output condition (e.g. 'SIG(A) && SIG(B)' will return ['A', 'B']
* @param condition
...
...
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