Skip to content
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

Save slate participant messages in database #2441

Merged
merged 12 commits into from
Jan 31, 2019

Conversation

yeastplume
Copy link
Member

@yeastplume yeastplume commented Jan 21, 2019

Alternative to #2409. Note that this stores messages within a struct in the database, and the actual formatting (if you want in in JSON, for instance,) can be applied somewhere higher up in the pipeline.

Messages + keys + sig for an output are displayed when showing details of a particular transaction, e.g. grin wallet txs -i 32.

Shouldn't break backwards compat, as the new stored message field in the TxLogEntry is Optional.

Messages are now limited to 256 (unicode) characters and will are truncated at the API level.

Todos:

  • Limit message length
  • Test backwards compat isn't broken
  • Check/fix serialization of message elements (or we're going to end up with long byte arrays on JSON output)

@yeastplume yeastplume changed the title [WIP] Save tx messages in database [WIP] Save slate participant messages in database Jan 21, 2019
@@ -30,3 +30,6 @@ chrono = "0.4.4"

grin_keychain = { path = "../keychain", version = "1.0.0" }
grin_util = { path = "../util", version = "1.0.0" }

[dev-dependencies]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyone have any major problems with this dev-dependency? Would rather avoid but seems best way to run serialization tests.

@yeastplume yeastplume changed the title [WIP] Save slate participant messages in database Save slate participant messages in database Jan 25, 2019
@yeastplume yeastplume added this to the 1.0.1 milestone Jan 25, 2019
@yeastplume
Copy link
Member Author

Think this is ready to begin review now.

Copy link
Contributor

@hashmap hashmap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok to merge, suggested some refactoring

@@ -640,6 +643,14 @@ where
None => w.parent_key_id(),
};

let message = match message {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: I'd suggest to introduce SlateMessage type and define semantic (it could be None, if not String has limited length) there, we truncate twice in this pr, could forget to do it introducing some new logic later on

}
let mut batch = wallet.batch()?;
for tx in tx_vec.into_iter() {
let mut t = tx.clone();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need t here? we consume tx_vec, could we use tx?

for tx in tx_vec.into_iter() {
let mut t = tx.clone();
t.messages = Some(slate.participant_messages());
batch.save_tx_log_entry(t.clone(), &t.parent_key_id.clone())?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to clone t here?

t.messages = Some(slate.participant_messages());
batch.save_tx_log_entry(t.clone(), &t.parent_key_id.clone())?;
}
batch.commit()?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd replace 2 lines with just batch.commit();

@hashmap
Copy link
Contributor

hashmap commented Jan 30, 2019

Actually enforcing string length using type system may not be that great idea after all, too many underlying levels must be changed

@yeastplume
Copy link
Member Author

Thanks for review, tightened up loop a bit. I'd started trying to enforce the message length a bit further down, but ran into issues as you say. So long as it's enforced at the API level (which is what most people will use, I think it should be okay).

@yeastplume yeastplume merged commit 0c851c5 into mimblewimble:master Jan 31, 2019
@yeastplume yeastplume deleted the save_tx_message branch January 31, 2019 11:56
@alesito85
Copy link

@yeastplume is there a way to identify which message belongs to the sender? Or is it always the first one in the array?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants