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

validate p2p messages and topics #1755

Merged
merged 10 commits into from
Apr 22, 2023
Merged

validate p2p messages and topics #1755

merged 10 commits into from
Apr 22, 2023

Conversation

onur-ozkan
Copy link
Member

@onur-ozkan onur-ozkan commented Apr 13, 2023

Applies the following checks:

  • Validate topics if they are mixed or not.
  • Do early return if the message data is not valid (since no point to iterate over and over on the invalid message)
  • Avoid decoding messages that have more than 25 topics
  • Break the loop right after processing any of SWAP_PREFIX, WATCHER_PREFIX, TX_HELPER_PREFIX topic.

Copy link
Member

@laruh laruh left a comment

Choose a reason for hiding this comment

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

Thanks for this fix!
Just a note for the first view and question: Why did you choose 25 topics limit?

mm2src/mm2_main/src/lp_network.rs Outdated Show resolved Hide resolved
@onur-ozkan
Copy link
Member Author

Why did you choose 25 topics limit?

25 topics can't hurt, and it's quite flexible value for any case I think.

Copy link
Member

@borngraced borngraced left a comment

Choose a reason for hiding this comment

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

Great work! got a question

mm2src/mm2_main/src/lp_network.rs Outdated Show resolved Hide resolved
mm2src/gossipsub/src/protocol.rs Outdated Show resolved Hide resolved
mm2src/mm2_main/src/lp_network.rs Outdated Show resolved Hide resolved
mm2src/gossipsub/src/protocol.rs Outdated Show resolved Hide resolved
mm2src/mm2_main/src/lp_network.rs Outdated Show resolved Hide resolved
mm2src/mm2_main/src/lp_network.rs Outdated Show resolved Hide resolved
@@ -90,7 +90,8 @@ pub use lp_bot::{start_simple_market_maker_bot, stop_simple_market_maker_bot, St

#[path = "lp_ordermatch/my_orders_storage.rs"]
mod my_orders_storage;
#[path = "lp_ordermatch/new_protocol.rs"] mod new_protocol;
#[path = "lp_ordermatch/new_protocol.rs"]
pub(crate) mod new_protocol;

Choose a reason for hiding this comment

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

It would be more clear it did not stick up, explained before

Copy link
Member Author

Choose a reason for hiding this comment

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

Can you clarify this, didn't understand it

Choose a reason for hiding this comment

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

Now it can be rolled back because stick up logic has been hidden

Copy link
Collaborator

Choose a reason for hiding this comment

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

Done

mm2src/mm2_main/src/lp_swap.rs Outdated Show resolved Hide resolved
mm2src/mm2_main/src/lp_swap.rs Outdated Show resolved Hide resolved
mm2src/mm2_main/src/lp_swap.rs Outdated Show resolved Hide resolved
mm2src/mm2_main/src/lp_swap/swap_watcher.rs Outdated Show resolved Hide resolved
@onur-ozkan onur-ozkan force-pushed the fix-p2p-stack branch 2 times, most recently from 1c62cc7 to 911bc31 Compare April 16, 2023 22:31
Signed-off-by: ozkanonur <work@onurozkan.dev>
@@ -92,7 +92,7 @@ const ABCI_REQUEST_PROVE: bool = false;
/// 0.25 is good average gas price on atom and iris
const DEFAULT_GAS_PRICE: f64 = 0.25;
pub(super) const TIMEOUT_HEIGHT_DELTA: u64 = 100;
pub const GAS_LIMIT_DEFAULT: u64 = 100_000;
pub const GAS_LIMIT_DEFAULT: u64 = 125_000;
Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Could you document(either here in the PR comments or in the changelog) why you are changing this value?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because HTLCs requiring more gas than our limit lately. Since gas prices can be updated from the coins configuration, this should never be problem even if we make it 200_000.

Signed-off-by: ozkanonur <work@onurozkan.dev>
Copy link
Collaborator

@shamardy shamardy left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the fix! Only one comment for now.

mm2src/gossipsub/src/protocol.rs Outdated Show resolved Hide resolved
Signed-off-by: ozkanonur <work@onurozkan.dev>
Copy link
Collaborator

@shamardy shamardy left a comment

Choose a reason for hiding this comment

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

Just some minor comments :)

mm2src/mm2_main/src/lp_network.rs Show resolved Hide resolved
mm2src/mm2_main/src/lp_network.rs Show resolved Hide resolved
mm2src/mm2_main/src/lp_ordermatch.rs Outdated Show resolved Hide resolved
@shamardy
Copy link
Collaborator

@ozkanonur please merge with latest dev that fixes the failing trade_test_electrum_and_eth_coins test

shamardy
shamardy previously approved these changes Apr 18, 2023
Copy link
Collaborator

@shamardy shamardy left a comment

Choose a reason for hiding this comment

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

🔥

@shamardy
Copy link
Collaborator

@rozhkovdmitrii can you please check if your comments have been fixed or not?
@borngraced @laruh will you be doing another review?

laruh
laruh previously approved these changes Apr 19, 2023
Copy link
Member

@laruh laruh left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks!

borngraced
borngraced previously approved these changes Apr 19, 2023
Copy link
Member

@borngraced borngraced left a comment

Choose a reason for hiding this comment

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

Great work and well done 🙌🏼 🔥

@shamardy shamardy dismissed stale reviews from borngraced, laruh, and themself via 240506f April 20, 2023 00:03
.find_order_by_uuid_and_pubkey(&uuid, &from_pubkey)
.ok_or_else(|| MmError::new(OrderbookP2PHandlerError::OrderNotFound(uuid)))?;
order.apply_updated(&updated_msg);
drop_mutability!(order);

Choose a reason for hiding this comment

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

Does it require to drop mutability explicitly?

Copy link
Collaborator

Choose a reason for hiding this comment

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

drop_mutability! is done to ensure that the order cannot be accidentally modified later in this part of the code.

@onur-ozkan onur-ozkan merged commit 547a30a into dev Apr 22, 2023
@onur-ozkan onur-ozkan deleted the fix-p2p-stack branch April 22, 2023 16:11
onur-ozkan added a commit that referenced this pull request Apr 24, 2023
* optimize p2p network layer

Signed-off-by: ozkanonur <work@onurozkan.dev>

* update default gas limit for tendermint

Signed-off-by: ozkanonur <work@onurozkan.dev>

* rollback topic limit

Signed-off-by: ozkanonur <work@onurozkan.dev>

* remove unused arg from `lp_ordermatch::process_msg`

Signed-off-by: ozkanonur <work@onurozkan.dev>

* use OrderbookP2PHandlerResult for process_orders_keep_alive and process_maker_order_updated

* return one error for failed SwapMsg, SwapStatus deserialization

* fix process_swap_msg in wasm to return error if SwapMsg can't be deserialized

* remove additional space in SwapMsg, SwapStatus decode error message

* roll back crate visibility for new_protocol mod

---------

Signed-off-by: ozkanonur <work@onurozkan.dev>
Co-authored-by: shamardy <shamardy@yahoo.com>
onur-ozkan added a commit that referenced this pull request Apr 24, 2023
Signed-off-by: ozkanonur <work@onurozkan.dev>
onur-ozkan added a commit that referenced this pull request Apr 26, 2023
Signed-off-by: ozkanonur <work@onurozkan.dev>
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.

7 participants