MCPcopy Create free account
hub / github.com/ElementsProject/lightning / raw_peer_connect

Function raw_peer_connect

tests/test_connection.py:5224–5252  ·  view source on GitHub ↗

Handshake to node as a raw peer, echoing back its own features. Returns the connection and a channel_type the node will accept.

(node)

Source from the content-addressed store, hash-verified

5222
5223
5224def raw_peer_connect(node):
5225 """Handshake to node as a raw peer, echoing back its own features.
5226
5227 Returns the connection and a channel_type the node will accept.
5228 """
5229 lconn = wire.connect(wire.PrivateKey(bytes([0x11] * 32)),
5230 wire.PublicKey(bytes.fromhex(node.info['id'])),
5231 '127.0.0.1', node.port)
5232
5233 # Echo their features back, so we never require one they lack.
5234 msg = lconn.read_message()
5235 assert int.from_bytes(msg[0:2], 'big') == WIRE_INIT, "expected init"
5236 payload = msg[2:]
5237
5238 glen = struct.unpack('>H', payload[0:2])[0]
5239 flen = struct.unpack('>H', payload[2 + glen:4 + glen])[0]
5240 theirs = payload[4 + glen:4 + glen + flen]
5241
5242 lconn.send_message(struct.pack('>HH', WIRE_INIT, 0)
5243 + struct.pack('>H', len(theirs)) + theirs)
5244
5245 # Without option_support_large_channel the 2^24 cap applies, and we never
5246 # reach the commitment transaction code this test is about.
5247 assert feature_offered(theirs, OPT_LARGE_CHANNELS), "peer does not offer wumbo"
5248
5249 ctype = featurebits(*[b for b in (OPT_STATIC_REMOTEKEY,
5250 OPT_ANCHORS_ZERO_FEE_HTLC_TX)
5251 if feature_offered(theirs, b)])
5252 return lconn, ctype
5253
5254
5255def send_open_channel(lconn, chain_hash, temp_chan_id, funding_sat, push_msat,

Calls 6

featurebitsFunction · 0.85
read_messageMethod · 0.80
send_messageMethod · 0.80
feature_offeredFunction · 0.70
connectMethod · 0.45
from_bytesMethod · 0.45

Tested by

no test coverage detected