Beispiel #1
0
def init(options: dict, configuration: dict, plugin: Plugin, **kwargs):
    plugin.our_node_id = plugin.rpc.getinfo()["id"]
    plugin.deactivate_fuzz = options.get("feeadjuster-deactivate-fuzz")
    plugin.forward_event_subscription = not options.get(
        "feeadjuster-deactivate-fee-update")
    plugin.update_threshold = float(options.get("feeadjuster-threshold"))
    plugin.update_threshold_abs = Millisatoshi(
        options.get("feeadjuster-threshold-abs"))
    plugin.big_enough_liquidity = Millisatoshi(
        options.get("feeadjuster-enough-liquidity"))
    plugin.imbalance = float(options.get("feeadjuster-imbalance"))
    adjustment_switch = {
        "soft": get_ratio_soft,
        "hard": get_ratio_hard,
        "default": get_ratio
    }
    plugin.get_ratio = adjustment_switch.get(
        options.get("feeadjuster-adjustment-method"), get_ratio)
    fee_strategy_switch = {
        "global": get_fees_global,
        "median": get_fees_median
    }
    plugin.fee_strategy = fee_strategy_switch.get(
        options.get("feeadjuster-feestrategy"), get_fees_global)
    config = plugin.rpc.listconfigs()
    plugin.adj_basefee = config["fee-base"]
    plugin.adj_ppmfee = config["fee-per-satoshi"]

    # normalize the imbalance percentage value to 0%-50%
    if plugin.imbalance < 0 or plugin.imbalance > 1:
        raise ValueError("feeadjuster-imbalance must be between 0 and 1.")
    if plugin.imbalance > 0.5:
        plugin.imbalance = 1 - plugin.imbalance

    # detect if server supports the new listchannels by `destination` (#4614)
    plugin.listchannels_by_dst = False
    rpchelp = plugin.rpc.help().get('help')
    if len([
            c for c in rpchelp if c["command"].startswith("listchannels ")
            and "destination" in c["command"]
    ]) == 1:
        plugin.listchannels_by_dst = True

    plugin.log(
        f"Plugin feeadjuster initialized "
        f"({plugin.adj_basefee} base / {plugin.adj_ppmfee} ppm) with an "
        f"imbalance of {int(100 * plugin.imbalance)}%/{int(100 * ( 1 - plugin.imbalance))}%, "
        f"update_threshold: {int(100 * plugin.update_threshold)}%, "
        f"update_threshold_abs: {plugin.update_threshold_abs}, "
        f"enough_liquidity: {plugin.big_enough_liquidity}, "
        f"deactivate_fuzz: {plugin.deactivate_fuzz}, "
        f"forward_event_subscription: {plugin.forward_event_subscription}, "
        f"adjustment_method: {plugin.get_ratio.__name__}, "
        f"fee_strategy: {plugin.fee_strategy.__name__}, "
        f"listchannels_by_dst: {plugin.listchannels_by_dst}")
    plugin.mutex.release()
    feeadjust(plugin)
Beispiel #2
0
def init(options: dict, configuration: dict, plugin: Plugin, **kwargs):
    plugin.our_node_id = plugin.rpc.getinfo()["id"]
    plugin.deactivate_fuzz = options.get("feeadjuster-deactivate-fuzz")
    plugin.forward_event_subscription = not options.get(
        "feeadjuster-deactivate-fee-update")
    plugin.update_threshold = float(options.get("feeadjuster-threshold"))
    plugin.update_threshold_abs = Millisatoshi(
        options.get("feeadjuster-threshold-abs"))
    plugin.big_enough_liquidity = Millisatoshi(
        options.get("feeadjuster-enough-liquidity"))
    plugin.imbalance = float(options.get("feeadjuster-imbalance"))
    adjustment_switch = {
        "soft": get_ratio_soft,
        "hard": get_ratio_hard,
        "default": get_ratio
    }
    plugin.get_ratio = adjustment_switch.get(
        options.get("feeadjuster-adjustment-method"), get_ratio)
    fee_strategy_switch = {
        "global": get_fees_global,
        "median": get_fees_median
    }
    plugin.fee_strategy = fee_strategy_switch.get(
        options.get("feeadjuster-feestrategy"), get_fees_global)
    config = plugin.rpc.listconfigs()
    plugin.adj_basefee = config["fee-base"]
    plugin.adj_ppmfee = config["fee-per-satoshi"]

    # normalize the imbalance percentage value to 0%-50%
    if plugin.imbalance < 0 or plugin.imbalance > 1:
        raise ValueError("feeadjuster-imbalance must be between 0 and 1.")
    if plugin.imbalance > 0.5:
        plugin.imbalance = 1 - plugin.imbalance

    plugin.log(
        f"Plugin feeadjuster initialized ({plugin.adj_basefee} base / {plugin.adj_ppmfee} ppm) with an "
        f"imbalance of {int(100 * plugin.imbalance)}%/{int(100 * ( 1 - plugin.imbalance))}%, "
        f"update_threshold: {int(100 * plugin.update_threshold)}%, update_threshold_abs: {plugin.update_threshold_abs}, "
        f"enough_liquidity: {plugin.big_enough_liquidity}, deactivate_fuzz: {plugin.deactivate_fuzz}, "
        f"forward_event_subscription: {plugin.forward_event_subscription}, adjustment_method: {plugin.get_ratio.__name__}"
    )
    plugin.mutex.release()
    feeadjust(plugin)