Commit Graph

711 Commits

Author SHA1 Message Date
Andrey Samokhvalov
06946f3911 htlcswitch: add real sphinx iterator
Before using the htlcswitch inside the lnd we need to implement the
sphinx version of the hop iterator, which will be process the real
onion blobs.
2017-05-31 11:06:08 -07:00
Andrey Samokhvalov
882aec704d htlcswitch: add channel link tests
Step #5 in making htlcManager (aka channelLink) testable:
Combine all that have been done so far and add test framework for channel
links which allow unit test:

* message ordering
* detect redundant messages
* single hop payment
* multihop payment
* several cancel payment scenarios
2017-05-31 11:06:08 -07:00
Andrey Samokhvalov
a14f25830e htlcswitch: remove redudant variables
Because processing of onion blob have been moved in another place we
could get rid of the variables which are not needed any more.

NOTE: pendingBatch have been replaced with batchCounter variable, but
it should be removed at all, because number of pending batch updates
might be counted by the state machine itself.
2017-05-31 11:06:08 -07:00
Andrey Samokhvalov
0e2209cb12 htlcswitch: move onion blob processing
Step №4 in making htlcManager (aka channelLink) testable:

This step consist of two:
1. Start using the hop iterator abstraction, the concrete
implementation of which will be added later, basically it will we the
same sphinx onion packet processor, but wrapped in hop iterator
abstraction.

2. The RevokAndAck processing part have been replaced by the
"processLockedInHtlcs" function which implement the same logic, but make
it a bit simpler.

Such changes will allow as to get rid of the the unnecessary variables.
2017-05-31 11:06:08 -07:00
Andrey Samokhvalov
de01721aed htlcswitch: add hop iterator
Short: such abstraction give as ability to test the channel link in the
future.

Long: hop iterator represents the entity which is be able to give payment
route hop by hop. This interface will be used to have an abstraction
over the algorithm which we use to determine the next hope in htlc route
and also helps the unit test to create mock representation of such
algorithm which uses simple array of hops.
2017-05-31 11:06:08 -07:00
Andrey Samokhvalov
db30571efe htlcswitch: start using config in channel link
Step №3 in making htlcManager (aka channelLink) testable:
Apply the channel link config inside the channel link itself.
2017-05-31 11:06:08 -07:00
Andrey Samokhvalov
2eea76375c htlcswitch: make channel link implements interface
Step №2 in making htlcManager (aka channelLink) testable:
Implement the ChannelLink interface which is needed to use it in pair
with htlc switch. With this commit channel link impelements interface,
but isn't able to operate properly yet.
2017-05-31 11:06:08 -07:00
Andrey Samokhvalov
7f572fc155 htlcswitch: add channel link config
Step №1 in making htlcManager (aka channelLink) testable:
Start use config which will allow as mock/stub external subsystems.
2017-05-31 11:06:08 -07:00
Andrey Samokhvalov
0de4ea2712 htlcswitch: copy the initial representation of htlc manager
In this commit all initial code which will be transformed into channel
link have been added. Rather than changing the in the same commit is
better to create the standalone commit, in order to see the changes
which have been applied to relocated code.
2017-05-31 11:06:08 -07:00
Andrey Samokhvalov
b86409cdb3 htlcswitch: recreate hlcswitch from scratch
This commit gives the start for making the htlc manager and htlc switch
testable. The testability of htlc switch have been achieved by mocking
all external subsystems. The concrete list of updates:

1. create standalone package for htlc switch.
2. add "ChannelLink" interface, which represent the previous htlc link.
3. add "Peer" interface, which represent the remote node inside our
subsystem.
4. add htlc switch config to htlc switch susbystem, which stores the
handlers which are not elongs to any of the above interfaces.

With this commit we are able test htlc switch even without having
the concrete implementation of Peer, ChannelLink structures, they will
be added later.
2017-05-31 11:06:08 -07:00
Andrey Samokhvalov
07afcad6de htlcswitch: add hop id
Add hop id structure wich represent the next lnd node in sphinx payment
route. This structure will be removed when we switch to use the channel
id as the pointers to the htlc update.
2017-05-31 11:06:08 -07:00