Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
polkadot-sdk
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
parity
Mirrored projects
polkadot-sdk
Commits
b8dbe46b
Commit
b8dbe46b
authored
2 years ago
by
Alexander Theißen
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Revert "Replace storage access by atomics" (#11156)
This reverts commit a69b8eb4a28f365a4a4b2fc295a693ec4d3d3cd5.
parent
6531ed74
Branches
Branches containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
substrate/frame/support/src/storage/mod.rs
+28
-26
28 additions, 26 deletions
substrate/frame/support/src/storage/mod.rs
with
28 additions
and
26 deletions
substrate/frame/support/src/storage/mod.rs
+
28
−
26
View file @
b8dbe46b
...
...
@@ -48,46 +48,48 @@ pub mod unhashed;
pub
mod
weak_bounded_vec
;
mod
transaction_level_tracker
{
use
core
::
sync
::
atomic
::{
AtomicU32
,
Ordering
};
type
Layer
=
u32
;
static
NUM_LEVELS
:
AtomicU32
=
AtomicU32
::
new
(
0
)
;
const
TRANSACTION_LEVEL_KEY
:
&
'static
[
u8
]
=
b":transaction_level:"
;
const
TRANSACTIONAL_LIMIT
:
Layer
=
255
;
pub
fn
get_transaction_level
()
->
Layer
{
NUM_LEVELS
.load
(
Ordering
::
SeqCst
)
crate
::
storage
::
unhashed
::
get_or_default
::
<
Layer
>
(
TRANSACTION_LEVEL_KEY
)
}
fn
set_transaction_level
(
level
:
&
Layer
)
{
crate
::
storage
::
unhashed
::
put
::
<
Layer
>
(
TRANSACTION_LEVEL_KEY
,
level
);
}
fn
kill_transaction_level
()
{
crate
::
storage
::
unhashed
::
kill
(
TRANSACTION_LEVEL_KEY
);
}
/// Increments the transaction level. Returns an error if levels go past the limit.
///
/// Returns a guard that when dropped decrements the transaction level automatically.
pub
fn
inc_transaction_level
()
->
Result
<
StorageLayerGuard
,
()
>
{
NUM_LEVELS
.fetch_update
(
Ordering
::
SeqCst
,
Ordering
::
SeqCst
,
|
existing_levels
|
{
if
existing_levels
>=
TRANSACTIONAL_LIMIT
{
return
None
}
// Cannot overflow because of check above.
Some
(
existing_levels
+
1
)
})
.map_err
(|
_
|
())
?
;
let
existing_levels
=
get_transaction_level
();
if
existing_levels
>=
TRANSACTIONAL_LIMIT
{
return
Err
(())
}
// Cannot overflow because of check above.
set_transaction_level
(
&
(
existing_levels
+
1
));
Ok
(
StorageLayerGuard
)
}
fn
dec_transaction_level
()
{
NUM_LEVELS
.fetch_update
(
Ordering
::
SeqCst
,
Ordering
::
SeqCst
,
|
existing_levels
|
{
if
existing_levels
==
0
{
log
::
warn!
(
"We are underflowing with calculating transactional levels. Not great, but let's not panic..."
,
);
None
}
else
{
// Cannot underflow because of checks above.
Some
(
existing_levels
-
1
)
}
})
.ok
();
let
existing_levels
=
get_transaction_level
();
if
existing_levels
==
0
{
log
::
warn!
(
"We are underflowing with calculating transactional levels. Not great, but let's not panic..."
,
);
}
else
if
existing_levels
==
1
{
// Don't leave any trace of this storage item.
kill_transaction_level
();
}
else
{
// Cannot underflow because of checks above.
set_transaction_level
(
&
(
existing_levels
-
1
));
}
}
pub
fn
is_transactional
()
->
bool
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
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