Don't use newest fork rules if server sends an earlier version

pull/27/head
Nathan Dorfman 5 years ago
parent 95b6528d91
commit d9aa140687

@ -36,7 +36,8 @@
#ifndef monero_fork_rules_hpp #ifndef monero_fork_rules_hpp
#define monero_fork_rules_hpp #define monero_fork_rules_hpp
#include "crypto.h" #include <functional>
#include <stdint.h>
namespace monero_fork_rules namespace monero_fork_rules
{ {
@ -44,6 +45,18 @@ namespace monero_fork_rules
// //
bool lightwallet_hardcoded__use_fork_rules(uint8_t version, int64_t early_blocks); // convenience - to be called by a use_fork_rules_fn_type implementation bool lightwallet_hardcoded__use_fork_rules(uint8_t version, int64_t early_blocks); // convenience - to be called by a use_fork_rules_fn_type implementation
// //
// The fork_version should be the actual current network fork version.
// If zero, it is ignored and the resulting functor always returns true.
inline use_fork_rules_fn_type make_use_fork_rules_fn(uint8_t fork_version)
{
return 0 != fork_version ?
[fork_version](uint8_t desired_version, int64_t/*early_blocks is ignored*/)
{
return desired_version <= fork_version;
}
: use_fork_rules_fn_type(lightwallet_hardcoded__use_fork_rules);
}
//
uint32_t fixed_ringsize(); // not mixinsize, which would be ringsize-1 uint32_t fixed_ringsize(); // not mixinsize, which would be ringsize-1
uint32_t fixed_mixinsize(); // not ringsize, which would be mixinsize+1 uint32_t fixed_mixinsize(); // not ringsize, which would be mixinsize+1
// //

@ -242,9 +242,11 @@ LightwalletAPI_Res_GetUnspentOuts monero_send_routine::new__parsed_res__get_unsp
unspent_outs.push_back(std::move(out)); unspent_outs.push_back(std::move(out));
} }
} }
auto fork_version = res.get_optional<uint8_t>("fork_version");
return LightwalletAPI_Res_GetUnspentOuts{ return LightwalletAPI_Res_GetUnspentOuts{
none, none,
final__per_byte_fee, fee_mask, unspent_outs final__per_byte_fee, fee_mask, unspent_outs,
fork_version ? *fork_version : static_cast<uint8_t>(0)
}; };
} }
LightwalletAPI_Res_GetRandomOuts monero_send_routine::new__parsed_res__get_random_outs( LightwalletAPI_Res_GetRandomOuts monero_send_routine::new__parsed_res__get_random_outs(
@ -312,6 +314,7 @@ struct _SendFunds_ConstructAndSendTx_Args
const vector<SpendableOutput> &unspent_outs; const vector<SpendableOutput> &unspent_outs;
uint64_t fee_per_b; uint64_t fee_per_b;
uint64_t fee_quantization_mask; uint64_t fee_quantization_mask;
uint8_t fork_version;
// //
// cached // cached
const secret_key &sec_viewKey; const secret_key &sec_viewKey;
@ -329,6 +332,8 @@ void _reenterable_construct_and_send_tx(
) { ) {
args.status_update_fn(calculatingFee); args.status_update_fn(calculatingFee);
// //
auto use_fork_rules = monero_fork_rules::make_use_fork_rules_fn(args.fork_version);
//
Send_Step1_RetVals step1_retVals; Send_Step1_RetVals step1_retVals;
monero_transfer_utils::send_step1__prepare_params_for_get_decoys( monero_transfer_utils::send_step1__prepare_params_for_get_decoys(
step1_retVals, step1_retVals,
@ -337,10 +342,7 @@ void _reenterable_construct_and_send_tx(
args.sending_amount, args.sending_amount,
args.is_sweeping, args.is_sweeping,
args.simple_priority, args.simple_priority,
[] (uint8_t version, int64_t early_blocks) -> bool use_fork_rules,
{
return lightwallet_hardcoded__use_fork_rules(version, early_blocks);
},
args.unspent_outs, args.unspent_outs,
args.fee_per_b, args.fee_per_b,
args.fee_quantization_mask, args.fee_quantization_mask,
@ -358,7 +360,8 @@ void _reenterable_construct_and_send_tx(
api_fetch_cb_fn get_random_outs_fn__cb_fn = [ api_fetch_cb_fn get_random_outs_fn__cb_fn = [
args, args,
step1_retVals, step1_retVals,
constructionAttempt constructionAttempt,
use_fork_rules
] ( ] (
const property_tree::ptree &res const property_tree::ptree &res
) -> void { ) -> void {
@ -386,10 +389,7 @@ void _reenterable_construct_and_send_tx(
args.fee_per_b, args.fee_per_b,
args.fee_quantization_mask, args.fee_quantization_mask,
*(parsed_res.mix_outs), *(parsed_res.mix_outs),
[] (uint8_t version, int64_t early_blocks) -> bool std::move(use_fork_rules),
{
return lightwallet_hardcoded__use_fork_rules(version, early_blocks);
},
args.unlock_time, args.unlock_time,
args.nettype args.nettype
); );
@ -527,6 +527,7 @@ void monero_send_routine::async__send_funds(Async_SendFunds_Args args)
*(parsed_res.unspent_outs), *(parsed_res.unspent_outs),
*(parsed_res.per_byte_fee), *(parsed_res.per_byte_fee),
*(parsed_res.fee_mask), *(parsed_res.fee_mask),
parsed_res.fork_version,
// //
sec_viewKey, sec_spendKey sec_viewKey, sec_spendKey
}); });

@ -202,6 +202,7 @@ namespace monero_send_routine
optional<uint64_t> per_byte_fee; optional<uint64_t> per_byte_fee;
optional<uint64_t> fee_mask; optional<uint64_t> fee_mask;
optional<vector<SpendableOutput>> unspent_outs; optional<vector<SpendableOutput>> unspent_outs;
uint8_t fork_version;
}; };
struct LightwalletAPI_Res_GetRandomOuts struct LightwalletAPI_Res_GetRandomOuts
{ {

Loading…
Cancel
Save