Browser node
Running in productionComing in 12.5.5

Browser node

A very thin Lotus node in a web page: what it verifies, how to include it in your site, what your node serves and shows.

Every node serves a small JavaScript library that makes a browser a very thin Lotus node. The page speaks the P2P protocol over WebSocket to several nodes, checks the proof of work and the difficulty of every header itself, follows the chain with the most work, and warns when nodes disagree. The web UI of a node starts it for every visitor.

What it does #

ConnectsTo 4 nodes by default, over ws:// or wss://.
VerifiesThe block hash, the target, the difficulty rule, the height, the epoch hash, the time rules and the pinned checkpoints of every header.
ChoosesThe chain with the most verified work.
WarnsA fork between peers, a peer that sends an invalid header, a conflict with a checkpoint, fewer than 2 peers, a tip older than an hour.
ProvesThat a transaction is in a block, by a merkle proof checked against a header it verified.
RelaysIts own transactions, and headers it has verified, to peers that lack them.
StoresThe headers from a checkpoint to the tip: 115 kB per day of chain.

It does not accept connections, mine, or validate blocks and transactions.

Include it in a site #

html
<script src="http://NODE:10604/lib/lotus-loader.js" defer
        data-chip="#lotus-status"></script>
<span id="lotus-status"></span>

The loader starts the node after the page has loaded, keeps one set of connections for all the tabs of the site, and shows a status chip. For the library alone:

html
<script src="http://NODE:10604/lib/lotus-node.js"></script>
<script>
Lotus.connect({network: 'mainnet', storage: true}).then(node => {
  node.on('tip', t => console.log(t.height, t.hash, t.proven));
  node.on('fork-alert', a => console.warn(a.type, a.message));
});
</script>
CallResult
node.getTip()Height, hash, time, proof, pending, agreement, peers.
node.getHeader(heightOrHash)A verified header, or null.
node.verifyTx(txid, {block})confirmed, height, position, confirmations, provenConfirmations.
node.watchAddress(address)tx events for that address.
node.broadcast(rawTxHex)txid, sentTo, seenBy.
node.peers(), node.stats()Peers and counters.
node.on(event, fn)tip, reorg, peer, fork-alert, tx, sync.

Secure pages #

A page served over https:// can only reach wss:// endpoints, so nodes that have a certificate. A page served over http:// reaches every node. On a secure site with no wss:// endpoint the loader waits quietly and starts by itself when one appears.

What your node serves #

RouteContent
/lib/lotus-node.js, /lib/lotus-node.mjsThe library, stamped with the node's version.
/lib/lotus-loader.jsThe loader and status chip.
/lib/demo.htmlA page that shows the node of your browser.
GET /api/v1/network/wsnodesThe WebSocket addresses browsers can use, and the library files with their SHA-256.

The files can be read from any origin. To publish the address browsers should use behind a reverse proxy:

Config
p2pwspublic=wss://node.example.org/p2p

How browsers appear on your node #

A browser announces itself as the release that served the library with the tag -browser:

Text
/lotusd:12.5.5-browser(lotus-node.js 0.2.0)/

The node reports the kind of every peer as kind in getpeerinfo and in GET /api/v1/network/peers:

KindPeer
fullA full node.
thinlotusd in thin mode.
desktopLotus Desktop.
browserA web page running the browser node.
otherOther software.

Only full nodes count in the software shares and in the upgrade notice. In the web UI, Network › Connected peers shows a badge per kind and the count of each; type browser in the filter to list them.

Napoleon upgrade

From the Napoleon activation a block may be proven by a parent-chain header carried in its metadata. The browser node fetches that block from the peer that announced it and checks the proof itself: the parent header's work at target / M (SHA-256d or Scrypt), the commitment to this very block, the anchor. Only then does the block count; getHeader(h).proof says parent-proof or own-hash. The tip is always the last block of a chain proven block by block; getTip().pending counts newer headers still waiting for their proof. Three rules stay with full nodes because they need the parent chains' history: one use per parent header, the proof building on a recorded parent header, and the exact lane difficulty. See Merged mining.

In the wallet #

The web wallet runs the browser node too, in a separate worker that never receives a key. The header then shows Block N · verified; each transaction of the history that is in a block is checked against the verified chain and marked verified; payments are given to several nodes at once; an incoming payment shows up as soon as a node relays it. The list of an address's transactions and coins still comes from the node that serves the wallet: it can leave one out, it cannot get a false one marked verified. Settings › Browser node in the wallet turns it off; the wallet then works on the node's word alone, as before.

Browsers on the Network map #

Every browser running the node shows on the Network map of the nodes it is connected to, as a small dot of its own colour; a Lotus Desktop app is a small square. The header of the map counts them: "14 nodes · 3 desktop · 240 browsers". The map grows as visitors arrive: the peers of this node at once, those of the other nodes within a few minutes. A visitor that leaves goes with the next report.

A browser is listed under a random id that changes with each session. Its address, its country and its network operator are never published: not on the map, not in GET /api/v1/network/peers, not in any route that needs no credentials. Only the operator of the node it is connected to sees the address, with getpeerinfo and the RPC credentials.

SharedNot shared
That a browser is connected to which nodes, and since when.The address and the country.
The version of the library, the height, the traffic of the link.The wallet, the addresses watched, the transactions.
A random id, new at each session.Anything about the person.

The visitor decides: Network › Browser node, Show this browser on the network map (on by default). Off, the nodes do not list the browser; they only count one more hidden connection. Lotus Desktop has the same switch.

Beyond 24 browsers around one node, or 120 on the map, the others are drawn as one dot with their number ("+226"); the header still counts each of them.

Note

A node older than 12.5.6 lists every peer with its address in its default sharing mode, and does not know the switch. Upgrade a node that takes browsers, or run it with -sharetopology=public until then.

With links on, a visitor's browser also connects directly to the browsers of other visitors and passes on to them the block headers it verified that are proven by their own hash: after Napoleon, directly mined blocks only. The browser keeps following the chain through nodes; a link is an extra path for announcements.

Two linked browsers see each other's public IP address, as in any direct connection. That is why links are off until the visitor turns them on (Network › Browser node, "Link directly to other visitors"), with that sentence next to the switch. The choice is remembered in the browser. Local network addresses stay hidden by the browser; nothing about the wallet or the pages visited travels on a link, only block headers and pings. The wallet page never links.

For operators: links need a node that helps two browsers find each other. It is off by default.

  • -p2pwsrtcrelay=1: the node passes the two setup messages between browsers that both asked for links. It never reads or keeps them, and never gives one browser the address of another.
  • Open UDP port 3478 (23478 on the test networks; -p2pwsrtcstunport=<port>): the node tells each browser its own public address there (STUN), so no outside service sees your visitors. -p2pwsrtcstun=<stun:host:port> adds servers of your own.
  • -p2pwsrtcmaxlinks=<n> (default 12): the most links one page keeps.

No relay server carries the traffic of a link: two browsers that cannot reach each other directly simply keep using nodes. Details and limits: doc/browser-node.md, "Browser links".

Turn it off #

In the web UI: Network › Browser node, Turn the browser node off. The choice is kept in that browser.

Source share/www/docs/browser-node.md in the lotusd repository
Checked against doc/browser-node.md share/www/lib/src/30-chain.js share/www/lib/src/40-node.js share/www/lib/lotus-loader.js src/api/browser_node_handler.cpp src/peerkind.h