-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Event V2 Translation #14615
Event V2 Translation #14615
Conversation
⏱️ 2h 42m total CI duration on this PR
|
50b9c0f
to
832b754
Compare
80c5021
to
bfbe123
Compare
123fbfe
to
27650b3
Compare
27650b3
to
c202506
Compare
ccd6843
to
c38fc96
Compare
32088d7
to
523e22f
Compare
b4c76bf
to
ea0bbbd
Compare
if let Some(seq) = self.get_cached_sequence_number(event_key) { | ||
Ok(seq + 1) | ||
} else { | ||
let seq = self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in what case you will find the data in database but not in cache?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cache and the database don't need to be perfectly synced as we don't plan to support the fast sync at the moment. When a node stops and resumes, we don't fill the cache with the data in the DB, and so the data may be present in the DB but not in the cache.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, what's wrong with loading it fully on startup? seems more straightforward
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we fully load it on startup, memory usage would continuously increase even after restarting the node. If we decide to support fast sync in the future, fully loading at startup would become necessary. At that point, I can revisit and update the code to accommodate that requirement.
ea0bbbd
to
660a1ab
Compare
api/src/context.rs
Outdated
if self.indexer_reader.is_some() | ||
&& self | ||
.node_config | ||
.indexer_db_config | ||
.enable_event_v2_translation | ||
{ | ||
self.translate_v2_to_v1_events_for_version(txn.version, &mut txn.events) | ||
.ok(); | ||
} | ||
Ok(txn) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Can we reduce the boilerplate a little by introducing
fn maybe_transalate_v2_events_to_v1(&self, txn: TransactionOnChainDate) -> TransactionOnChainData
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your comments. I introduced maybe_translate_v2_to_v1_events
and refactored the code accordingly.
let mut translators: HashMap<TypeTag, Box<dyn EventV2Translator + Send + Sync>> = | ||
HashMap::new(); | ||
translators.insert(COIN_DEPOSIT_TYPE.clone(), Box::new(CoinDepositTranslator)); | ||
translators.insert(COIN_WITHDRAW_TYPE.clone(), Box::new(CoinWithdrawTranslator)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can't we do a literal array and build the hashmap from there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated it, building the hashmap from an array.
if let Some(seq) = self.get_cached_sequence_number(event_key) { | ||
Ok(seq + 1) | ||
} else { | ||
let seq = self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, what's wrong with loading it fully on startup? seems more straightforward
let group_tag_str = "0x1::object::ObjectGroup".to_string(); | ||
let group_tag = StructTag::from_str(&group_tag_str)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ObjectGroupResource::struct_tag()
also maybe worth caching it?
stretch: add StateKey::resource_group_typed::<MoveStruct>(address)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the code using ObjectGroupResource::struct_tag()
and caching it.
660a1ab
to
f52c1bc
Compare
|
||
impl EventV2TranslationEngine { | ||
pub fn new(main_db_reader: Arc<dyn DbReader>, internal_indexer_db: Arc<DB>) -> Self { | ||
let translators: HashMap<TypeTag, Box<dyn EventV2Translator + Send + Sync>> = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well.. the .clone
and Box::new
can be done in a map()
, no?
(Guess it's too messy to type the translator constructor, I'm gonna approve)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it does seem tricky to get the typing to work...
d137eea
to
a8d65f4
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
a8d65f4
to
c9a36c5
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ Forge suite
|
✅ Forge suite
|
✅ Forge suite
|
Description
This PR introduces the Event V2 Translation Engine, a framework for translating well-known V2 events into V1 format. So, the Node APIs can output those events in the V1 format.
Added the new flag
enable_event_v2_translation
to the node config for feature-gating.Added the event translators for the account and coin module events, translating:
Added the event translators for token objects and token v1 module events as well.
Implemented the e2e API test environment where we can simulate and test the module event migration. And, added the e2e tests for the event transaction for the account and coin modules.
Type of Change
Which Components or Systems Does This Change Impact?
How Has This Been Tested?
Tested on the localnet.
Added various e2e API tests.
Key Areas to Review
Checklist