Beispiel #1
0
def send_pfs_update(
    raiden: "RaidenService",
    canonical_identifier: CanonicalIdentifier,
    update_fee_schedule: bool = False,
) -> None:
    if raiden.routing_mode == RoutingMode.PRIVATE:
        return

    channel_state = views.get_channelstate_by_canonical_identifier(
        chain_state=views.state_from_raiden(raiden), canonical_identifier=canonical_identifier
    )

    if channel_state is None:
        return

    capacity_msg = PFSCapacityUpdate.from_channel_state(channel_state)
    capacity_msg.sign(raiden.signer)
    raiden.transport.send_global(constants.PATH_FINDING_BROADCASTING_ROOM, capacity_msg)
    log.debug("Sent a PFS Capacity Update", message=capacity_msg, channel_state=channel_state)

    if update_fee_schedule:
        fee_msg = PFSFeeUpdate.from_channel_state(channel_state)
        fee_msg.sign(raiden.signer)

        raiden.transport.send_global(constants.PATH_FINDING_BROADCASTING_ROOM, fee_msg)
        log.debug("Sent a PFS Fee Update", message=fee_msg, channel_state=channel_state)
Beispiel #2
0
def test_update_pfs():
    properties = factories.BalanceProofSignedStateProperties(pkey=PRIVKEY)
    balance_proof = factories.create(properties)
    channel_state = factories.create(factories.NettingChannelStateProperties())
    channel_state.our_state.balance_proof = balance_proof
    channel_state.partner_state.balance_proof = balance_proof
    message = PFSCapacityUpdate.from_channel_state(channel_state=channel_state)

    assert message.signature == EMPTY_SIGNATURE
    privkey2, address2 = factories.make_privkey_address()
    signer2 = LocalSigner(privkey2)
    message.sign(signer2)
    assert recover(message._data_to_sign(), message.signature) == address2

    assert message == DictSerializer.deserialize(DictSerializer.serialize(message))