Skip to content

Commit

Permalink
sphinx: Cleanup route_step_decode_* functions
Browse files Browse the repository at this point in the history
We have consolidated the two functions into a single `route_step_decode`
function, and made it static since we call it in the `process_onionpacket`
function. We remove the two exposed functions since they're no longer useful.
  • Loading branch information
cdecker committed Nov 19, 2019
1 parent 7a4ea37 commit 78ca90e
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 96 deletions.
71 changes: 0 additions & 71 deletions common/sphinx.c
Original file line number Diff line number Diff line change
Expand Up @@ -923,74 +923,3 @@ struct onionreply *unwrap_onionreply(const tal_t *ctx,
return oreply;

}

/**
* Helper to extract fields from ONION_END.
*/
bool route_step_decode_end(const struct route_step *rs,
struct amount_msat *amt_forward,
u32 *outgoing_cltv)
{
assert(rs->nextcase == ONION_END);

switch (rs->type) {
case SPHINX_V0_PAYLOAD:
*amt_forward = rs->payload.v0.amt_forward;
*outgoing_cltv = rs->payload.v0.outgoing_cltv;
return true;
case SPHINX_TLV_PAYLOAD:
if (!rs->payload.tlv->amt_to_forward)
return false;
if (!rs->payload.tlv->outgoing_cltv_value)
return false;
amt_forward->millisatoshis /* Raw: tu64 -> millisatoshis */
= rs->payload.tlv->amt_to_forward->amt_to_forward;
*outgoing_cltv = rs->payload.tlv->outgoing_cltv_value->outgoing_cltv_value;
return true;
case SPHINX_INVALID_PAYLOAD:
return false;

/* This should probably be removed, as it's just for testing */
case SPHINX_RAW_PAYLOAD:
abort();
}
abort();
}

/**
* Helper to extract fields from ONION_FORWARD.
*/
bool route_step_decode_forward(const struct route_step *rs,
struct amount_msat *amt_forward,
u32 *outgoing_cltv,
struct short_channel_id *scid)
{
assert(rs->nextcase == ONION_FORWARD);

switch (rs->type) {
case SPHINX_V0_PAYLOAD:
*amt_forward = rs->payload.v0.amt_forward;
*outgoing_cltv = rs->payload.v0.outgoing_cltv;
*scid = rs->payload.v0.channel_id;
return true;
case SPHINX_TLV_PAYLOAD:
if (!rs->payload.tlv->amt_to_forward)
return false;
amt_forward->millisatoshis /* Raw: tu64 -> millisatoshis */
= rs->payload.tlv->amt_to_forward->amt_to_forward;
if (!rs->payload.tlv->outgoing_cltv_value)
return false;
*outgoing_cltv = rs->payload.tlv->outgoing_cltv_value->outgoing_cltv_value;
if (!rs->payload.tlv->short_channel_id)
return false;
*scid = rs->payload.tlv->short_channel_id->short_channel_id;
return true;
case SPHINX_INVALID_PAYLOAD:
return false;

/* This should probably be removed, as it's just for testing */
case SPHINX_RAW_PAYLOAD:
abort();
}
abort();
}
14 changes: 0 additions & 14 deletions common/sphinx.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,18 +249,4 @@ void sphinx_add_final_hop(struct sphinx_path *path,
struct amount_msat forward,
u32 outgoing_cltv);

/**
* Helper to extract fields from ONION_END.
*/
bool route_step_decode_end(const struct route_step *rs,
struct amount_msat *amt_forward,
u32 *outgoing_cltv);

/**
* Helper to extract fields from ONION_FORWARD.
*/
bool route_step_decode_forward(const struct route_step *rs,
struct amount_msat *amt_forward,
u32 *outgoing_cltv,
struct short_channel_id *scid);
#endif /* LIGHTNING_COMMON_SPHINX_H */
11 changes: 0 additions & 11 deletions wallet/test/run-wallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -524,17 +524,6 @@ struct route_step *process_onionpacket(
const size_t assocdatalen
)
{ fprintf(stderr, "process_onionpacket called!\n"); abort(); }
/* Generated stub for route_step_decode_end */
bool route_step_decode_end(const struct route_step *rs UNNEEDED,
struct amount_msat *amt_forward UNNEEDED,
u32 *outgoing_cltv UNNEEDED)
{ fprintf(stderr, "route_step_decode_end called!\n"); abort(); }
/* Generated stub for route_step_decode_forward */
bool route_step_decode_forward(const struct route_step *rs UNNEEDED,
struct amount_msat *amt_forward UNNEEDED,
u32 *outgoing_cltv UNNEEDED,
struct short_channel_id *scid UNNEEDED)
{ fprintf(stderr, "route_step_decode_forward called!\n"); abort(); }
/* Generated stub for serialize_onionpacket */
u8 *serialize_onionpacket(
const tal_t *ctx UNNEEDED,
Expand Down

0 comments on commit 78ca90e

Please sign in to comment.