Skip to content

Commit

Permalink
devp2p -> LES: unifiy ETH and LES sendMessage() signature by somewhat…
Browse files Browse the repository at this point in the history
… change payload semantics and pass in reqId along
  • Loading branch information
holgerd77 committed Feb 7, 2021
1 parent 39d7edb commit 4063ffd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions packages/devp2p/src/les/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,12 @@ export class LES extends EventEmitter {
this._handleStatus()
}

sendMessage(code: LES.MESSAGE_CODES, reqId: number, payload: any) {
/**
*
* @param code Message code
* @param payload Payload (including reqId, e.g. `[1, [437000, 1, 0, 0]]`)
*/
sendMessage(code: LES.MESSAGE_CODES, payload: any) {
const debugMsg = `Send ${this.getMsgPrefix(code)} message to ${
this._peer._socket.remoteAddress
}:${this._peer._socket.remotePort}`
Expand Down Expand Up @@ -197,7 +202,7 @@ export class LES extends EventEmitter {
throw new Error(`Unknown code ${code}`)
}

this._send(code, rlp.encode([reqId, payload]))
this._send(code, rlp.encode(payload))
}

getMsgPrefix(msgCode: LES.MESSAGE_CODES) {
Expand Down
4 changes: 2 additions & 2 deletions packages/devp2p/test/integration/les-simulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ test('LES: send valid message', async (t) => {
opts.status1 = Object.assign({}, status)
opts.onOnceStatus0 = function (rlpxs: any, les: any) {
t.equal(les.getVersion(), 2, 'should use les2 as protocol version')
les.sendMessage(devp2p.LES.MESSAGE_CODES.GET_BLOCK_HEADERS, 1, [437000, 1, 0, 0])
les.sendMessage(devp2p.LES.MESSAGE_CODES.GET_BLOCK_HEADERS, [1, [437000, 1, 0, 0]])
t.pass('should send GET_BLOCK_HEADERS message')
}
opts.onOnMsg1 = function (rlpxs: any, eth: any, code: any) {
Expand All @@ -104,7 +104,7 @@ test('LES: send unknown message code', async (t) => {
opts.status1 = Object.assign({}, status)
opts.onOnceStatus0 = function (rlpxs: any, les: any) {
try {
les.sendMessage(0x55, 1, [])
les.sendMessage(0x55, [1, []])
} catch (err) {
const msg = 'Error: Unknown code 85'
t.equal(err.toString(), msg, `should emit error: ${msg}`)
Expand Down

0 comments on commit 4063ffd

Please sign in to comment.