-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Messages] Reception and confirmation times
Added two new fields to the messages collection. We now store the initial time of reception of a message in the `reception_time` field, and the earliest on-chain confirmation time in the `confirmation_time` field. These fields will be used to order messages more precisely/securely and to compute metrics, for example the propagation time of a message on the network. The `time` field of messages is now deprecated, as it is defined by users and not signed. If you need the user time, use `content.time`.
- Loading branch information
1 parent
f4446ff
commit d70793f
Showing
13 changed files
with
117 additions
and
16 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
deployment/migrations/scripts/0004-create-new-message-time-fields.py
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,32 @@ | ||
""" | ||
This migration adds the `confirmation_time` and `reception_time` fields. | ||
`confirmation_time` serves as a cache of the first confirmation message seen | ||
in on-chain data. | ||
`reception_time` represents the first time the node became aware of | ||
the message, confirmed or not. | ||
""" | ||
|
||
|
||
import logging | ||
import os | ||
|
||
from configmanager import Config | ||
|
||
from aleph.model.messages import Message | ||
|
||
logger = logging.getLogger(os.path.basename(__file__)) | ||
|
||
|
||
async def upgrade(config: Config, **kwargs): | ||
logger.info("Creating confirmation_time field for messages...") | ||
await Message.collection.update_many( | ||
{"confirmed": True}, | ||
[{"$set": {"confirmation_time": {"$min": "$confirmations.time"}}}], | ||
) | ||
|
||
|
||
async def downgrade(**kwargs): | ||
logger.info("Creating confirmation_time field for messages...") | ||
await Message.collection.update_many( | ||
{"$unset": {"confirmation_time": 1, "reception_time": 1}} | ||
) |
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.