-
Couldn't load subscription status.
- Fork 21
Internal: store the full TX context in confirmations #265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
odesenfans
merged 2 commits into
aleph-im:dev
from
odesenfans:od-pass-tx-context-to-incoming
Oct 13, 2022
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.