-
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.
Internal: store the full TX context in confirmations (#265)
We now store the entire context of the transaction in the confirmations array of messages. This means that two additional fields are now preserved: the transaction block timestamp and the publisher. As we need to re-fetch this data from chain data, a new migration script resets the chain height to re-process all transactions. We reset the confirmation status of all messages to unconfirmed and deleted their confirmations array to let the node automatically migrate to the new format. Renamed some fields of the `TxContext` class in order to use the same format in all DB collections and to avoid a breaking change in the messages confirmation format.
- Loading branch information
1 parent
8c51cf5
commit f4446ff
Showing
13 changed files
with
152 additions
and
99 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
deployment/migrations/scripts/0003-retrieve-confirmation-time.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,48 @@ | ||
""" | ||
This migration retrieves additional metadata regarding chain confirmation of messages, | ||
including the block timestamp. We reset the TX height of the node to reprocess | ||
all the chain data messages and insert additional values | ||
""" | ||
|
||
|
||
import logging | ||
import os | ||
from configmanager import Config | ||
from aleph.model.chains import Chain | ||
from aleph.model.pending import PendingMessage, PendingTX | ||
from aleph.model.messages import Message | ||
|
||
logger = logging.getLogger(os.path.basename(__file__)) | ||
|
||
|
||
async def upgrade(config: Config, **kwargs): | ||
logger.info("Resetting chain height to re-fetch all chaindata...") | ||
start_height = config.ethereum.start_height.value | ||
await Chain.set_last_height("ETH", start_height) | ||
|
||
logger.info("Dropping all pending transactions...") | ||
await PendingTX.collection.delete_many({}) | ||
|
||
logger.info( | ||
"Dropping all pending confirmation messages " | ||
"(they will be reinserted automatically)..." | ||
) | ||
await PendingMessage.collection.delete_many({"source.chain_name": {"$ne": None}}) | ||
|
||
logger.info("Removing confirmation data for all messages...") | ||
# Confirmations will be automatically added again by the pending TX processor. | ||
# By removing the confirmation entirely, we make sure to avoid intermediate states | ||
# if a message was confirmed in an unexpected way. | ||
await Message.collection.update_many( | ||
{"confirmed": True}, | ||
{ | ||
"$set": { | ||
"confirmed": False, | ||
}, | ||
"$unset": {"confirmations": 1}, | ||
}, | ||
) | ||
|
||
|
||
async def downgrade(**kwargs): | ||
raise NotImplementedError("Downgrading this migration is not supported.") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
from dataclasses import dataclass | ||
from aleph.schemas.message_confirmation import MessageConfirmation | ||
|
||
|
||
@dataclass | ||
class TxContext: | ||
chain_name: str | ||
tx_hash: str | ||
height: int | ||
# Transaction timestamp, in Unix time (number of seconds since epoch). | ||
time: int | ||
publisher: str | ||
# At the moment, confirmation = chain transaction. This might change, but in the meantime | ||
# having TxContext inherit MessageConfirmation avoids code duplication. | ||
class TxContext(MessageConfirmation): | ||
pass |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from aleph_message.models import Chain | ||
from pydantic import BaseModel, Field | ||
|
||
|
||
class MessageConfirmation(BaseModel): | ||
chain: Chain = Field(..., description="Chain from which the confirmation was fetched.") | ||
height: int = Field(..., description="Block in which the confirmation was published.") | ||
hash: str = Field( | ||
..., | ||
description="Hash of the transaction/block in which the confirmation was published.", | ||
) | ||
time: float = Field( | ||
..., | ||
description="Transaction timestamp, in Unix time (number of seconds since epoch).", | ||
) | ||
publisher: str = Field(..., description="Publisher of the confirmation on chain.") |
Oops, something went wrong.