mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-09 09:04:25 +01:00
shachain: shachain_get_secret helper.
This is a wrapper around shachain_get_hash, which converts the commit_num to an index and returns a 'struct secret' rather than a 'struct sha256' (which is really an internal detail). Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
692bae7873
commit
b123b1867d
@@ -228,3 +228,16 @@ void fromwire_basepoints(const u8 **ptr, size_t *max,
|
||||
fromwire_pubkey(ptr, max, &b->htlc);
|
||||
fromwire_pubkey(ptr, max, &b->delayed_payment);
|
||||
}
|
||||
|
||||
bool shachain_get_secret(const struct shachain *shachain,
|
||||
u64 commit_num,
|
||||
struct secret *preimage)
|
||||
{
|
||||
struct sha256 sha;
|
||||
|
||||
if (!shachain_get_hash(shachain, shachain_index(commit_num), &sha))
|
||||
return false;
|
||||
BUILD_ASSERT(sizeof(*preimage) == sizeof(sha));
|
||||
memcpy(preimage, &sha, sizeof(*preimage));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -145,6 +145,10 @@ static inline u64 revocations_received(const struct shachain *shachain)
|
||||
return (1ULL << SHACHAIN_BITS) - (shachain_next_index(shachain) + 1);
|
||||
}
|
||||
|
||||
bool shachain_get_secret(const struct shachain *shachain,
|
||||
u64 commit_num,
|
||||
struct secret *preimage);
|
||||
|
||||
void towire_basepoints(u8 **pptr, const struct basepoints *b);
|
||||
void fromwire_basepoints(const u8 **ptr, size_t *max,
|
||||
struct basepoints *b);
|
||||
|
||||
@@ -1698,7 +1698,7 @@ static void steal_htlc(struct tracked_output *out)
|
||||
static void handle_their_cheat(const struct bitcoin_tx *tx,
|
||||
const struct bitcoin_txid *txid,
|
||||
u32 tx_blockheight,
|
||||
const struct sha256 *revocation_preimage,
|
||||
const struct secret *revocation_preimage,
|
||||
const struct basepoints basepoints[NUM_SIDES],
|
||||
const struct htlc_stub *htlcs,
|
||||
const bool *tell_if_missing,
|
||||
@@ -2223,7 +2223,7 @@ int main(int argc, char *argv[])
|
||||
* party crashed, for instance. One side publishes its
|
||||
* *latest commitment transaction*.
|
||||
*/
|
||||
struct sha256 revocation_preimage;
|
||||
struct secret revocation_preimage;
|
||||
commit_num = unmask_commit_number(tx, funder,
|
||||
&basepoints[LOCAL].payment,
|
||||
&basepoints[REMOTE].payment);
|
||||
@@ -2246,9 +2246,8 @@ int main(int argc, char *argv[])
|
||||
* *outdated commitment transaction* (presumably, a prior
|
||||
* version, which is more in its favor).
|
||||
*/
|
||||
else if (shachain_get_hash(&shachain,
|
||||
shachain_index(commit_num),
|
||||
&revocation_preimage)) {
|
||||
else if (shachain_get_secret(&shachain, commit_num,
|
||||
&revocation_preimage)) {
|
||||
handle_their_cheat(tx, &txid,
|
||||
tx_blockheight,
|
||||
&revocation_preimage,
|
||||
|
||||
@@ -81,6 +81,11 @@ void master_badmsg(u32 type_expected UNNEEDED, const u8 *msg)
|
||||
/* Generated stub for peer_billboard */
|
||||
void peer_billboard(bool perm UNNEEDED, const char *fmt UNNEEDED, ...)
|
||||
{ fprintf(stderr, "peer_billboard called!\n"); abort(); }
|
||||
/* Generated stub for shachain_get_secret */
|
||||
bool shachain_get_secret(const struct shachain *shachain UNNEEDED,
|
||||
u64 commit_num UNNEEDED,
|
||||
struct secret *preimage UNNEEDED)
|
||||
{ fprintf(stderr, "shachain_get_secret called!\n"); abort(); }
|
||||
/* Generated stub for status_failed */
|
||||
void status_failed(enum status_failreason code UNNEEDED,
|
||||
const char *fmt UNNEEDED, ...)
|
||||
|
||||
Reference in New Issue
Block a user