Skip to content

refactor: reverse trait system#255

Merged
sedited merged 17 commits intofarcaster-project:mainfrom
h4sh3d:refactor/types-and-traits
Jul 11, 2022
Merged

refactor: reverse trait system#255
sedited merged 17 commits intofarcaster-project:mainfrom
h4sh3d:refactor/types-and-traits

Conversation

@h4sh3d
Copy link
Member

@h4sh3d h4sh3d commented Jul 8, 2022

Rework of the trait system used in the library to push everything at the surface. Allows better types handling in the future.

This introduces a list of surface breaking changes, to have a good idea see tests/protocol.rs which test the high level API of the lib.

Remove global Ctx
The most significant change is removing the global context Ctx: Swap which was defined on the type BtcXmr, example of changes:

-Alice<BtcXmr>
+Alice<Address, Btc, Xmr>

or

-PublicOffer<BtcXmr>
+PublicOffer<bitcoin::Amount, monero::Amount, CSVTimelock, SatPerVByte>,

These changes are applied to all protocol::message (protocol_message old) so it become possible and standard to e.g. use derive(..) macros.

Remove bundles
The second significant change is the removal of bundle types. Bundles was design in RFCs as message exchanged between microservices. Those types are currently defined, as it should be, in the node directly.

To not over-bloat this already bloated PR I'll now continue on separate PRs based on this one, so we can do a review process with @TheCharlatan.

Fix #252, fix #245

Resources: dtolay about "trait bounds on structs"

h4sh3d added 14 commits July 6, 2022 15:59
first step to refactor serde in this library.
Simplify trait bounds on TaggedElement and take direct generic on
AccordantKeys and AccordandKeySet instead of nested generic.
Move protocol_message into the new protocol module. Modify the generic
argument to split the context into multiple generic. Add more derives on
types.

This commit prepare the removing of bundles from core. They are in fact
messages created inside node already. It also prepare the migration of
execution logic on Alice and Bob into the new protocol module.
Alice and Bob logic is migrated into protocol module.
This huge refactor rework all the trait system used in the library to
push types to the surface instead of having one context: Swap.

This allows more flexibility but refactor is not completly done, some
trait should be removed and some should be split, e.g. crypto::Sign, to
allow less generics in protocol functions.

This refactor allows proper implementation/derivation on messages that
are used in node and passed over the network.
@h4sh3d h4sh3d requested a review from sedited July 11, 2022 07:25
@h4sh3d h4sh3d added this to the v0.5.0 milestone Jul 11, 2022
@h4sh3d h4sh3d marked this pull request as ready for review July 11, 2022 07:39
Copy link
Contributor

@sedited sedited left a comment

Choose a reason for hiding this comment

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

I don't understand some things going on in this change, but I think I have a good overview of the set of changes now. I don't want to spend more time on this, so I will give my approval for this to go ahead. This has some clear benefits and I like that the "god-type" BtcXmr was removed and replaced with more fine grained controls.

I also feel like this allows us to eventually actually use the swap implementation as defined in swap/ without having to resort to many of the lower-level definitions.

@sedited sedited merged commit bda0cc4 into farcaster-project:main Jul 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove bundles from core lib Update monero to version 0.17.0

2 participants