# Auditing V2: Random Node Selection ## Abstract This design doc outlines how we will implement a Version 2 of the auditing service. With our current auditing service, we are auditing per segment of data. We propose to replace this method of auditing with a new selection process that selects by random node instead. ## Background As our network grows, it will take longer for nodes to get vetted. This is because every time an upload happens, we send 5% of the uploaded data to unvetted nodes and 95% to vetted nodes. When auditing occurs, we currently select a random stripe within a random segment. If we're selecting audits at random per byte, every segment has some percentage that went to vetted nodes. As more nodes join the network, it will become exponentially less likely that an unvetted node will be audited since most data will be stored on vetted nodes. With a satellite with one petabyte of data, new nodes will take one month to get vetted. However, with 12PB of data on the network, this vetting process time would take 12 months, which is much too long. We need a scalable approach. We want a way to select segments to audit based on statistically randomly selected storage nodes. Currently, there's not a way to select a random storage node and audit on that basis. ## Design We will create an audit observer that uses the metainfo loop, and this observer will create a reservoir sample of segments for every node. This audit observer will replace the existing method of auditing per byte. The observer will loop through all of metainfo and build a reservoir cache for each node. The audit will then pick a configurable number of random nodes, then a random segment to audit from each of the nodes' reservoirs. If each segment generates 80 pieces on average, every time we pick a segment, we're not only auditing one specific node, we're also auditing 79 other nodes. The chance of a node appearing in a segment's pointer is proportional to the amount of data that the node actually stores. The more data that the node stores, the more chance it will be audited. We will set a minimum number of audits for unvetted nodes, and expect more audits for nodes that store more data. After selection, the rest of the auditing process will occur the same way as it does currently: picking a random segment, picking a random stripe, downloading all erasure shares associated with that stripe and using Berlekamp-Welch algorithm (via the Infectious library) to verify that they haven't been altered. The chances of selecting the same stripe are rare, but it's normal/expected behavior if occasionally a stripe is audited more than once. We plan to run a simulation for this new method of auditing so we can estimate appropriate settings around reservoir sampling. If we decide that we want to prefer nodes with less audits, then we will implement the power of two choices, in which we randomly select two nodes, then choose the one with less audits. This would still require tracking number of audits, but it would prevent having to sort and query all nodes by audit count, which could cause undesirable behavior. For example, when new nodes join the network, the audit system could become stuck auditing only new nodes, and ignoring more established nodes. We are expecting close to 3 audits per day for unvetted nodes. The satellite currently issues one audit every 30 seconds, the current interval, which gives us close to 3,000 audits per day. There are about 1,000 nodes on the network currently. This could mean that the default size of a reservoir should be three, if we assume a full iteration of reservoirs in one day. ### Selection via Reservoir Sampling Reservoir sampling: a family of algorithms for randomly choosing a sample of items with uniform probability from a stream of data (of unknown size). As the audit observer uses the metainfo loop to iterate through the pointerdb, we're going through all segments and creating reservoirs per node, and filling the reservoirs with segments to audit. In order to increase the amount of audits for unvetted nodes, we can build larger reservoir samples for unvetted nodes. Two configurations for reservoir sampling: number of segments per unvetted nodes, and for vetted. E.g. If nodes n000, n002, and n003 are vetted, they will have less reservoir slots than unvetted nodes n001 and n004. n000 + + + + n001 + + + + + + + n002 + + + + n003 + + + + n004 + + + + + + + Unvetted nodes should get 25,000 pieces per month. On a good day, there will be 1000 pieces added to an unvetted node, which should quickly fill the reservoir sample. • We have a reservoir of k items and a stream of n items, where n is an unknown number. • Fill the reservoir from [0...k-1] with the first k items in the stream • For every item in the stream from index i=k..n-1, pick a random number j=rand(0..i), and if j