-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge PR #2334: ADR for global message counter
- Loading branch information
1 parent
18d5b04
commit b09e859
Showing
3 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
File renamed without changes.
54 changes: 54 additions & 0 deletions
54
docs/architecture/decision-records/adr-001-message-counter.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# ADR 001: Global Message Counter | ||
|
||
## Context | ||
|
||
There is a desire for modules to have a concept of orderings between messages. | ||
|
||
One such example is in staking, we currently use an "intra bond tx counter" and | ||
bond height. | ||
The purpose these two serve is to providing an ordering for validators with equal stake, | ||
for usage in the power-ranking of validators. | ||
We can't use address here, as that would create a bad incentive to grind | ||
addresses that optimized the sort function, which lowers the private key's | ||
security. | ||
Instead we order by whose transaction appeared first, as tracked by bondHeight | ||
and intra bond tx counter. | ||
|
||
This logic however should not be unique to staking. | ||
It is very conceivable that many modules in the future will want to be able to | ||
know the ordering of messages / objects after they were initially created. | ||
|
||
## Decision | ||
|
||
Create a global message counter field of type int64. | ||
Note that with int64's, there is no fear of overflow under normal use, | ||
as it is only getting incremented by one, | ||
and thus has a space of 9 quintillion values to go through. | ||
|
||
This counter must be persisted in state, but can just be read and written on | ||
begin/end block respectively. | ||
This field will get incremented upon every DeliverTx, | ||
regardless if the transaction succeeds or not. | ||
It must also be incremented within the check state for CheckTx. | ||
The global message ordering field should be set within the context | ||
so that modules can access it. | ||
|
||
## Corollary - Intra block ordering | ||
In the event that there is desire to just have an intra block msg counter, | ||
this can easily be derived from the global message counter. | ||
Simply subtract current counter from first global message counter in the block. | ||
Thus the relevant module could easily implement this. | ||
|
||
## Status | ||
Proposed | ||
|
||
## Consequences | ||
|
||
### Positive | ||
* Moves message ordering out of the set of things staking must keep track of | ||
* Abstracts the logic well so other modules can use it | ||
|
||
### Negative | ||
* Another thing to implement prelaunch. (Though this should be easy to implement) | ||
|
||
### Neutral |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters