diff --git a/contracts/NodesV2.sol b/contracts/NodesV2.sol index 9411772..7638eb5 100644 --- a/contracts/NodesV2.sol +++ b/contracts/NodesV2.sol @@ -9,11 +9,12 @@ contract NodesV2 // Nodes that have not passed any check or failed previous check Enode[] public inactiveNodes; - uint quorum; + uint16 quorum; + uint16 maxNodes = 6000; // How many blocks is a session - uint blockPerSession; + uint16 blockPerSession; uint currentSessionStart; - uint public currentSession; + uint32 public currentSession; struct Enode { bytes publicKey; @@ -25,6 +26,10 @@ contract NodesV2 uint lastTimeHasVoted; // For which voting round are the votes referring to uint lastTimeHasBeenVoted; + // Session when the node joine + uint32 joiningSession; + // Session when became active + uint32 activeSession; } mapping(address => uint) activeNodeIndex; @@ -35,7 +40,7 @@ contract NodesV2 _; } - constructor(uint _blockPerSession) + constructor(uint16 _blockPerSession) public { owner = msg.sender; @@ -52,16 +57,16 @@ contract NodesV2 } } - function getNode(uint index) public view returns (bytes memory, uint32, uint16) { + function getNode(uint index) public view returns (bytes memory, uint32, uint16, uint32, uint32) { Enode memory enode = activeNodes[index]; - return (enode.publicKey, enode.ip, enode.port); + return (enode.publicKey, enode.ip, enode.port, enode.joiningSession, enode.activeSession); } - function getInactiveNode(uint index) public view returns (bytes memory, uint32, uint16) { + function getInactiveNode(uint index) public view returns (bytes memory, uint32, uint16, uint32, uint32) { Enode memory enode = inactiveNodes[index]; - return (enode.publicKey, enode.ip, enode.port); + return (enode.publicKey, enode.ip, enode.port, enode.joiningSession, enode.activeSession); } @@ -73,8 +78,10 @@ contract NodesV2 require(msg.sender == publicKeyToAddress(publicKey)); // Make sure they haven't registered already require(activeNodeIndex[msg.sender] == 0 && inactiveNodeIndex[msg.sender] == 0); + // Make sure we don't hit the max nodes limit + require(activeNodes.length + inactiveNodes.length < maxNodes); - Enode memory _node = Enode(publicKey, ip, port, 0, 0, 0, 0); + Enode memory _node = Enode(publicKey, ip, port, 0, 0, 0, 0, currentSession, 0); inactiveNodes.push(_node); inactiveNodeIndex[msg.sender] = inactiveNodes.length; } @@ -120,6 +127,10 @@ contract NodesV2 // Make sure it has not voted already require(activeNodes[enodeIndex - 1].lastTimeHasVoted != currentSession); + + // Make sure it has not just became active, we allow 0 to ease bootstrapping + require(activeNodes[enodeIndex - 1].activeSession == 0 && activeNodes[enodeIndex - 1].activeSession != currentSession); + activeNodes[enodeIndex - 1].lastTimeHasVoted = currentSession; // Remove nodes that failed the vote @@ -156,6 +167,7 @@ contract NodesV2 if (enode.joinVotes == quorum) { Enode memory enodeCopy = inactiveNodes[index - 1]; + enodeCopy.activeSession = currentSession; _deleteInactiveNode(index - 1); _addActiveNode(enodeAddress, enodeCopy); } @@ -179,8 +191,10 @@ contract NodesV2 address enodeAddress = publicKeyToAddress(publicKey); // Make sure they haven't registered already require(activeNodeIndex[enodeAddress] == 0 && inactiveNodeIndex[enodeAddress] == 0); + // Make sure we don't hit the max nodes limit + require(activeNodes.length + inactiveNodes.length < maxNodes); - Enode memory _node = Enode(publicKey, ip, port, 0, 0, 0, 0); + Enode memory _node = Enode(publicKey, ip, port, 0, 0, 0, 0, currentSession, currentSession); _addActiveNode(enodeAddress, _node); @@ -197,8 +211,8 @@ contract NodesV2 } - function calculateQuorum(uint a) pure internal returns (uint ) { - return a / 2 + 1; + function calculateQuorum(uint a) pure internal returns (uint16) { + return uint16(a) / 2 + 1; } function _deleteInactiveNode(uint index) internal { diff --git a/golang/nodes/nodesv2.go b/golang/nodes/nodesv2.go index d9b0448..7448a14 100644 --- a/golang/nodes/nodesv2.go +++ b/golang/nodes/nodesv2.go @@ -28,13 +28,13 @@ var ( ) // NodesV2ABI is the input ABI used to generate the binding from. -const NodesV2ABI = "[{\"constant\":true,\"inputs\":[],\"name\":\"getCurrentSession\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"publicKey\",\"type\":\"bytes\"}],\"name\":\"publicKeyToAddress\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"pure\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"index\",\"type\":\"uint256\"}],\"name\":\"getNode\",\"outputs\":[{\"name\":\"\",\"type\":\"bytes\"},{\"name\":\"\",\"type\":\"uint32\"},{\"name\":\"\",\"type\":\"uint16\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"publicKey\",\"type\":\"bytes\"}],\"name\":\"registered\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"publicKey\",\"type\":\"bytes\"},{\"name\":\"ip\",\"type\":\"uint32\"},{\"name\":\"port\",\"type\":\"uint16\"}],\"name\":\"registerNode\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"inactiveNodeCount\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"inactiveNodes\",\"outputs\":[{\"name\":\"publicKey\",\"type\":\"bytes\"},{\"name\":\"ip\",\"type\":\"uint32\"},{\"name\":\"port\",\"type\":\"uint16\"},{\"name\":\"joinVotes\",\"type\":\"uint8\"},{\"name\":\"removeVotes\",\"type\":\"uint8\"},{\"name\":\"lastTimeHasVoted\",\"type\":\"uint256\"},{\"name\":\"lastTimeHasBeenVoted\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"activeNodeCount\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"index\",\"type\":\"uint256\"}],\"name\":\"getInactiveNode\",\"outputs\":[{\"name\":\"\",\"type\":\"bytes\"},{\"name\":\"\",\"type\":\"uint32\"},{\"name\":\"\",\"type\":\"uint16\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"activeNodes\",\"outputs\":[{\"name\":\"publicKey\",\"type\":\"bytes\"},{\"name\":\"ip\",\"type\":\"uint32\"},{\"name\":\"port\",\"type\":\"uint16\"},{\"name\":\"joinVotes\",\"type\":\"uint8\"},{\"name\":\"removeVotes\",\"type\":\"uint8\"},{\"name\":\"lastTimeHasVoted\",\"type\":\"uint256\"},{\"name\":\"lastTimeHasBeenVoted\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"joinNodes\",\"type\":\"address[]\"},{\"name\":\"removeNodes\",\"type\":\"address[]\"}],\"name\":\"vote\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"currentSession\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"publicKey\",\"type\":\"bytes\"},{\"name\":\"ip\",\"type\":\"uint32\"},{\"name\":\"port\",\"type\":\"uint16\"}],\"name\":\"addActiveNode\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"_blockPerSession\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"fallback\"}]" +const NodesV2ABI = "[{\"constant\":true,\"inputs\":[],\"name\":\"getCurrentSession\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"publicKey\",\"type\":\"bytes\"}],\"name\":\"publicKeyToAddress\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"pure\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"index\",\"type\":\"uint256\"}],\"name\":\"getNode\",\"outputs\":[{\"name\":\"\",\"type\":\"bytes\"},{\"name\":\"\",\"type\":\"uint32\"},{\"name\":\"\",\"type\":\"uint16\"},{\"name\":\"\",\"type\":\"uint32\"},{\"name\":\"\",\"type\":\"uint32\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"publicKey\",\"type\":\"bytes\"}],\"name\":\"registered\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"publicKey\",\"type\":\"bytes\"},{\"name\":\"ip\",\"type\":\"uint32\"},{\"name\":\"port\",\"type\":\"uint16\"}],\"name\":\"registerNode\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"inactiveNodeCount\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"inactiveNodes\",\"outputs\":[{\"name\":\"publicKey\",\"type\":\"bytes\"},{\"name\":\"ip\",\"type\":\"uint32\"},{\"name\":\"port\",\"type\":\"uint16\"},{\"name\":\"joinVotes\",\"type\":\"uint8\"},{\"name\":\"removeVotes\",\"type\":\"uint8\"},{\"name\":\"lastTimeHasVoted\",\"type\":\"uint256\"},{\"name\":\"lastTimeHasBeenVoted\",\"type\":\"uint256\"},{\"name\":\"joiningSession\",\"type\":\"uint32\"},{\"name\":\"activeSession\",\"type\":\"uint32\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"activeNodeCount\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"index\",\"type\":\"uint256\"}],\"name\":\"getInactiveNode\",\"outputs\":[{\"name\":\"\",\"type\":\"bytes\"},{\"name\":\"\",\"type\":\"uint32\"},{\"name\":\"\",\"type\":\"uint16\"},{\"name\":\"\",\"type\":\"uint32\"},{\"name\":\"\",\"type\":\"uint32\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"activeNodes\",\"outputs\":[{\"name\":\"publicKey\",\"type\":\"bytes\"},{\"name\":\"ip\",\"type\":\"uint32\"},{\"name\":\"port\",\"type\":\"uint16\"},{\"name\":\"joinVotes\",\"type\":\"uint8\"},{\"name\":\"removeVotes\",\"type\":\"uint8\"},{\"name\":\"lastTimeHasVoted\",\"type\":\"uint256\"},{\"name\":\"lastTimeHasBeenVoted\",\"type\":\"uint256\"},{\"name\":\"joiningSession\",\"type\":\"uint32\"},{\"name\":\"activeSession\",\"type\":\"uint32\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"joinNodes\",\"type\":\"address[]\"},{\"name\":\"removeNodes\",\"type\":\"address[]\"}],\"name\":\"vote\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"currentSession\",\"outputs\":[{\"name\":\"\",\"type\":\"uint32\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"publicKey\",\"type\":\"bytes\"},{\"name\":\"ip\",\"type\":\"uint32\"},{\"name\":\"port\",\"type\":\"uint16\"}],\"name\":\"addActiveNode\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"_blockPerSession\",\"type\":\"uint16\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"fallback\"}]" // NodesV2Bin is the compiled bytecode used for deploying new contracts. -const NodesV2Bin = `0x608060405234801561001057600080fd5b50604051602080611b7e8339810180604052602081101561003057600080fd5b5051600080546001600160a01b0319163317815560065543600555600455611b218061005d6000396000f3fe6080604052600436106100c25760003560e01c806372460fa81161007f57806396f9d9831161005957806396f9d9831461054c578063a19e39e814610576578063d4166763146106a6578063dad7bcee146106bb576100c2565b806372460fa814610421578063753408151461050d57806393696e1a14610522576100c2565b80631401795f146100cf57806343ae656c146100f65780634f0f4aa9146101c35780635aca952e1461028757806363cd6e181461034c5780636d1c76c21461040c575b36156100cd57600080fd5b005b3480156100db57600080fd5b506100e461077b565b60408051918252519081900360200190f35b34801561010257600080fd5b506101a76004803603602081101561011957600080fd5b810190602081018135600160201b81111561013357600080fd5b82018360208201111561014557600080fd5b803590602001918460018302840111600160201b8311171561016657600080fd5b91908080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525092955061079e945050505050565b604080516001600160a01b039092168252519081900360200190f35b3480156101cf57600080fd5b506101ed600480360360208110156101e657600080fd5b50356107b0565b60405180806020018463ffffffff1663ffffffff1681526020018361ffff1661ffff168152602001828103825285818151815260200191508051906020019080838360005b8381101561024a578181015183820152602001610232565b50505050905090810190601f1680156102775780820380516001836020036101000a031916815260200191505b5094505050505060405180910390f35b34801561029357600080fd5b50610338600480360360208110156102aa57600080fd5b810190602081018135600160201b8111156102c457600080fd5b8201836020820111156102d657600080fd5b803590602001918460018302840111600160201b831117156102f757600080fd5b91908080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152509295506108ec945050505050565b604080519115158252519081900360200190f35b34801561035857600080fd5b506100cd6004803603606081101561036f57600080fd5b810190602081018135600160201b81111561038957600080fd5b82018360208201111561039b57600080fd5b803590602001918460018302840111600160201b831117156103bc57600080fd5b91908080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152509295505050813563ffffffff169250506020013561ffff1661093f565b34801561041857600080fd5b506100e4610ae5565b34801561042d57600080fd5b5061044b6004803603602081101561044457600080fd5b5035610aeb565b60405180806020018863ffffffff1663ffffffff1681526020018761ffff1661ffff1681526020018660ff1660ff1681526020018560ff1660ff168152602001848152602001838152602001828103825289818151815260200191508051906020019080838360005b838110156104cc5781810151838201526020016104b4565b50505050905090810190601f1680156104f95780820380516001836020036101000a031916815260200191505b509850505050505050505060405180910390f35b34801561051957600080fd5b506100e4610bd5565b34801561052e57600080fd5b506101ed6004803603602081101561054557600080fd5b5035610bdb565b34801561055857600080fd5b5061044b6004803603602081101561056f57600080fd5b5035610bf5565b34801561058257600080fd5b506100cd6004803603604081101561059957600080fd5b810190602081018135600160201b8111156105b357600080fd5b8201836020820111156105c557600080fd5b803590602001918460208302840111600160201b831117156105e657600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295949360208101935035915050600160201b81111561063557600080fd5b82018360208201111561064757600080fd5b803590602001918460208302840111600160201b8311171561066857600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250929550610c02945050505050565b3480156106b257600080fd5b506100e4611062565b3480156106c757600080fd5b506100cd600480360360608110156106de57600080fd5b810190602081018135600160201b8111156106f857600080fd5b82018360208201111561070a57600080fd5b803590602001918460018302840111600160201b8311171561072b57600080fd5b91908080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152509295505050813563ffffffff169250506020013561ffff16611068565b6000610785611143565b15610796575060065460010161079b565b506006545b90565b8051602090910120606090811b901c90565b60606000806107bd611965565b600185815481106107ca57fe5b6000918252602091829020604080516004939093029091018054600260018216156101009081026000190190921604601f81018690049095028401810190925260e083018481529293909284929091849184018282801561086c5780601f106108415761010080835404028352916020019161086c565b820191906000526020600020905b81548152906001019060200180831161084f57829003601f168201915b5050509183525050600182015463ffffffff811660208084019190915261ffff600160201b83041660408085019190915260ff600160301b840481166060860152600160381b9093049092166080840152600284015460a084015260039093015460c0909201919091528251918301519201519097919650945092505050565b6000806108f88361079e565b6001600160a01b03811660009081526007602052604090205490915015801561093757506001600160a01b038116600090815260086020526040902054155b159392505050565b6109488361079e565b6001600160a01b0316336001600160a01b03161461096557600080fd5b3360009081526007602052604090205415801561098f575033600090815260086020526040902054155b61099857600080fd5b6109a0611965565b506040805160e08101825284815263ffffffff841660208083019190915261ffff8416928201929092526000606082018190526080820181905260a0820181905260c08201819052600280546001810180835591909252825180519394919385936004027f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace0192610a359284929101906119a1565b506020828101516001830180546040808701516060880151608089015163ffffffff1990941663ffffffff9096169590951765ffff000000001916600160201b61ffff909216919091021766ff0000000000001916600160301b60ff958616021767ff000000000000001916600160381b949092169390930217905560a084015160028085019190915560c090940151600390930192909255915433600090815260089093529120555050505050565b60025490565b60028181548110610af857fe5b60009182526020918290206004919091020180546040805160026001841615610100026000190190931692909204601f810185900485028301850190915280825291935091839190830182828015610b915780601f10610b6657610100808354040283529160200191610b91565b820191906000526020600020905b815481529060010190602001808311610b7457829003601f168201915b5050505060018301546002840154600390940154929363ffffffff82169361ffff600160201b840416935060ff600160301b8404811693600160381b900416919087565b60015490565b6060600080610be8611965565b600285815481106107ca57fe5b60018181548110610af857fe5b610c0a611143565b15610c1757610c17611150565b3360009081526007602052604090205480610c3157600080fd5b600654600180830381548110610c4357fe5b9060005260206000209060040201600201541415610c6057600080fd5b600654600180830381548110610c7257fe5b600091825260208220600260049092020101919091555b8251811015610d8857600060076000858481518110610ca457fe5b60200260200101516001600160a01b03166001600160a01b0316815260200190815260200160002054905080600014610d7f576000600180830381548110610ce857fe5b90600052602060002090600402019050600654816003015414610d2b57600654600382015560018101805467ff000000000000001916600160381b179055610d59565b6001808201805460ff600160381b80830482169094011690920267ff00000000000000199092169190911790555b6003546001820154600160381b900460ff161415610d7d57610d7d6001830361116e565b505b50600101610c89565b5060005b835181101561105c576000848281518110610da357fe5b6020908102919091018101516001600160a01b03811660009081526008909252604090912054909150801561105257600060026001830381548110610de457fe5b6000918252602091829020600490910201805460408051601f60026000196101006001871615020190941693909304928301859004850281018501909152818152919350610e8a92849190830182828015610e805780601f10610e5557610100808354040283529160200191610e80565b820191906000526020600020905b815481529060010190602001808311610e6357829003601f168201915b505050505061079e565b6001600160a01b0316836001600160a01b031614610ea757600080fd5b600654816003015414610ed957600654600382015560018101805466ff0000000000001916600160301b179055610f06565b6001808201805460ff600160301b80830482169094011690920266ff000000000000199092169190911790555b6003546001820154600160301b900460ff16141561105057610f26611965565b60026001840381548110610f3657fe5b6000918252602091829020604080516004939093029091018054600260018216156101009081026000190190921604601f81018690049095028401810190925260e0830184815292939092849290918491840182828015610fd85780601f10610fad57610100808354040283529160200191610fd8565b820191906000526020600020905b815481529060010190602001808311610fbb57829003601f168201915b5050509183525050600182015463ffffffff8116602083015261ffff600160201b820416604083015260ff600160301b820481166060840152600160381b909104166080820152600282015460a082015260039091015460c090910152905061104460001984016114f6565b61104e8482611858565b505b505b5050600101610d8c565b50505050565b60065481565b6000546001600160a01b0316331461107f57600080fd5b600061108a8461079e565b6001600160a01b0381166000908152600760205260409020549091501580156110c957506001600160a01b038116600090815260086020526040902054155b6110d257600080fd5b6110da611965565b6040518060e001604052808681526020018563ffffffff1681526020018461ffff168152602001600060ff168152602001600060ff168152602001600081526020016000815250905061112d8282611858565b6001546111399061195b565b6003555050505050565b6004546005540143101590565b60015461115c9061195b565b60035560068054600101905543600555565b600154811061117c57600080fd5b611184611965565b6001828154811061119157fe5b6000918252602091829020604080516004939093029091018054600260018216156101009081026000190190921604601f81018690049095028401810190925260e08301848152929390928492909184918401828280156112335780601f1061120857610100808354040283529160200191611233565b820191906000526020600020905b81548152906001019060200180831161121657829003601f168201915b5050509183525050600182015463ffffffff8116602083015261ffff600160201b820416604083015260ff600160301b820481166060840152600160381b909104166080820152600282015460a082015260039091015460c090910152805190915060009060079082906112a69061079e565b6001600160a01b031681526020810191909152604001600020556001805460001981019081106112d257fe5b9060005260206000209060040201600183815481106112ed57fe5b906000526020600020906004020160008201816000019080546001816001161561010002031660029004611322929190611a1f565b5060018281018054838301805463ffffffff191663ffffffff90921691909117808255825461ffff600160201b91829004160265ffff000000001990911617808255825460ff600160301b91829004811690910266ff00000000000019909216919091178083559254600160381b908190049091160267ff00000000000000199092169190911790556002808401549083015560039283015492909101919091558054806113cc57fe5b600082815260208120600019909201916004830201906113ec8282611a94565b506001818101805467ffffffffffffffff1916905560006002830181905560039092019190915591555482146114f25760606001838154811061142b57fe5b6000918252602091829020600490910201805460408051601f60026000196101006001871615020190941693909304928301859004850281018501909152818152928301828280156114be5780601f10611493576101008083540402835291602001916114be565b820191906000526020600020905b8154815290600101906020018083116114a157829003601f168201915b5050505050905082600101600760006114d68461079e565b6001600160a01b03168152602081019190915260400160002055505b5050565b600254811061150457600080fd5b61150c611965565b6002828154811061151957fe5b6000918252602091829020604080516004939093029091018054600260018216156101009081026000190190921604601f81018690049095028401810190925260e08301848152929390928492909184918401828280156115bb5780601f10611590576101008083540402835291602001916115bb565b820191906000526020600020905b81548152906001019060200180831161159e57829003601f168201915b5050509183525050600182015463ffffffff8116602083015261ffff600160201b820416604083015260ff600160301b820481166060840152600160381b909104166080820152600282015460a082015260039091015460c0909101528051909150600090600890829061162e9061079e565b6001600160a01b0316815260208101919091526040016000205560028054600019810190811061165a57fe5b90600052602060002090600402016002838154811061167557fe5b9060005260206000209060040201600082018160000190805460018160011615610100020316600290046116aa929190611a1f565b5060018281018054918301805463ffffffff191663ffffffff90931692909217808355815461ffff600160201b91829004160265ffff000000001990911617808355815460ff600160301b91829004811690910266ff00000000000019909216919091178084559154600160381b908190049091160267ff000000000000001990911617905560028083015481830155600392830154929091019190915580548061175157fe5b600082815260208120600019909201916004830201906117718282611a94565b5060018101805467ffffffffffffffff191690556000600280830182905560039092015591555482146114f2576060600283815481106117ad57fe5b6000918252602091829020600490910201805460408051601f60026000196101006001871615020190941693909304928301859004850281018501909152818152928301828280156118405780601f1061181557610100808354040283529160200191611840565b820191906000526020600020905b81548152906001019060200180831161182357829003601f168201915b5050505050905082600101600860006114d68461079e565b600180548082018083556000929092528251805184926004027fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf601916118a3918391602001906119a1565b5060208281015160018381018054604080880151606089015160808a015163ffffffff1990941663ffffffff9097169690961765ffff000000001916600160201b61ffff909216919091021766ff0000000000001916600160301b60ff968716021767ff000000000000001916600160381b959092169490940217905560a0850151600285015560c09094015160039093019290925591546001600160a01b0395909516600090815260079092529020929092555050565b6002900460010190565b6040805160e081018252606080825260006020830181905292820183905281018290526080810182905260a0810182905260c081019190915290565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106119e257805160ff1916838001178555611a0f565b82800160010185558215611a0f579182015b82811115611a0f5782518255916020019190600101906119f4565b50611a1b929150611adb565b5090565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10611a585780548555611a0f565b82800160010185558215611a0f57600052602060002091601f016020900482015b82811115611a0f578254825591600101919060010190611a79565b50805460018160011615610100020316600290046000825580601f10611aba5750611ad8565b601f016020900490600052602060002090810190611ad89190611adb565b50565b61079b91905b80821115611a1b5760008155600101611ae156fea165627a7a72305820c401d15488e9031dc72063821358c73d9ea26eb79694593a5364c6d0579696b10029` +const NodesV2Bin = `0x60806040526003805463ffff00001916631770000017905534801561002357600080fd5b50604051602080611f278339810180604052602081101561004357600080fd5b5051600080546001600160a01b031916331790556005805463ffffffff19169055436004556003805461ffff9092166401000000000265ffff0000000019909216919091179055611e8e806100996000396000f3fe6080604052600436106100c25760003560e01c806372460fa81161007f57806396f9d9831161005957806396f9d98314610562578063a19e39e81461058c578063d4166763146106bc578063dad7bcee146106ea576100c2565b806372460fa81461042d578063753408151461052357806393696e1a14610538576100c2565b80631401795f146100cf57806343ae656c146100f65780634f0f4aa9146101c35780635aca952e1461029357806363cd6e18146103585780636d1c76c214610418575b36156100cd57600080fd5b005b3480156100db57600080fd5b506100e46107aa565b60408051918252519081900360200190f35b34801561010257600080fd5b506101a76004803603602081101561011957600080fd5b810190602081018135600160201b81111561013357600080fd5b82018360208201111561014557600080fd5b803590602001918460018302840111600160201b8311171561016657600080fd5b91908080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152509295506107dc945050505050565b604080516001600160a01b039092168252519081900360200190f35b3480156101cf57600080fd5b506101ed600480360360208110156101e657600080fd5b50356107ee565b6040805163ffffffff80871660208084019190915261ffff87169383019390935284811660608301528316608082015260a080825287519082015286519091829160c083019189019080838360005b8381101561025457818101518382015260200161023c565b50505050905090810190601f1680156102815780820380516001836020036101000a031916815260200191505b50965050505050505060405180910390f35b34801561029f57600080fd5b50610344600480360360208110156102b657600080fd5b810190602081018135600160201b8111156102d057600080fd5b8201836020820111156102e257600080fd5b803590602001918460018302840111600160201b8311171561030357600080fd5b91908080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525092955061095e945050505050565b604080519115158252519081900360200190f35b34801561036457600080fd5b506100cd6004803603606081101561037b57600080fd5b810190602081018135600160201b81111561039557600080fd5b8201836020820111156103a757600080fd5b803590602001918460018302840111600160201b831117156103c857600080fd5b91908080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152509295505050813563ffffffff169250506020013561ffff166109b1565b34801561042457600080fd5b506100e4610bbc565b34801561043957600080fd5b506104576004803603602081101561045057600080fd5b5035610bc2565b6040805163ffffffff808b1660208084019190915261ffff8b169383019390935260ff808a1660608401528816608083015260a0820187905260c0820186905284811660e083015283166101008201526101208082528b51908201528a51909182916101408301918d019080838360005b838110156104e05781810151838201526020016104c8565b50505050905090810190601f16801561050d5780820380516001836020036101000a031916815260200191505b509a505050505050505050505060405180910390f35b34801561052f57600080fd5b506100e4610cbe565b34801561054457600080fd5b506101ed6004803603602081101561055b57600080fd5b5035610cc4565b34801561056e57600080fd5b506104576004803603602081101561058557600080fd5b5035610ce1565b34801561059857600080fd5b506100cd600480360360408110156105af57600080fd5b810190602081018135600160201b8111156105c957600080fd5b8201836020820111156105db57600080fd5b803590602001918460208302840111600160201b831117156105fc57600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295949360208101935035915050600160201b81111561064b57600080fd5b82018360208201111561065d57600080fd5b803590602001918460208302840111600160201b8311171561067e57600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250929550610cee945050505050565b3480156106c857600080fd5b506106d1611249565b6040805163ffffffff9092168252519081900360200190f35b3480156106f657600080fd5b506100cd6004803603606081101561070d57600080fd5b810190602081018135600160201b81111561072757600080fd5b82018360208201111561073957600080fd5b803590602001918460018302840111600160201b8311171561075a57600080fd5b91908080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152509295505050813563ffffffff169250506020013561ffff16611255565b60006107b4611371565b156107ce575060055463ffffffff908116600101166107d9565b5060055463ffffffff165b90565b8051602090910120606090811b901c90565b60606000806000806107fe611cc2565b6001878154811061080b57fe5b600091825260209182902060408051600593909302909101805460026001821615610100026000190190911604601f810185900490940283016101409081019092526101208301848152929390928492909184918401828280156108b05780601f10610885576101008083540402835291602001916108b0565b820191906000526020600020905b81548152906001019060200180831161089357829003601f168201915b5050509183525050600182015463ffffffff808216602080850191909152600160201b80840461ffff16604080870191909152600160301b850460ff9081166060880152600160381b9095049094166080860152600286015460a0860152600386015460c086015260049095015480831660e0808701919091529590049091166101009384015284519085015191850151938501519490920151919b909a5091985091965090945092505050565b60008061096a836107dc565b6001600160a01b0381166000908152600660205260409020549091501580156109a957506001600160a01b038116600090815260076020526040902054155b159392505050565b6109ba836107dc565b6001600160a01b0316336001600160a01b0316146109d757600080fd5b33600090815260066020526040902054158015610a01575033600090815260076020526040902054155b610a0a57600080fd5b6003546002546001546201000090920461ffff16910110610a2a57600080fd5b610a32611cc2565b50604080516101208101825284815263ffffffff80851660208084019190915261ffff8516938301939093526000606083018190526080830181905260a0830181905260c083018190526005805490921660e0840152610100830181905260028054600181018083559190925283518051949591948694939093027f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace0192610add9284920190611d0e565b506020828101516001830180546040808701516060880151608089015163ffffffff1994851663ffffffff9788161765ffff000000001916600160201b61ffff90941684021766ff0000000000001916600160301b60ff938416021767ff000000000000001916600160381b92909116919091021790935560a087015160028088019190915560c0880151600388015560e08801516004909701805461010090990151989093169685169690961767ffffffff000000001916969093169091029490941790935590543360009081526007909252919020555050505050565b60025490565b60028181548110610bcf57fe5b60009182526020918290206005919091020180546040805160026001841615610100026000190190931692909204601f810185900485028301850190915280825291935091839190830182828015610c685780601f10610c3d57610100808354040283529160200191610c68565b820191906000526020600020905b815481529060010190602001808311610c4b57829003601f168201915b50505050600183015460028401546003850154600490950154939463ffffffff80841695600160201b80860461ffff169650600160301b860460ff90811696600160381b90041694939280831692919091041689565b60015490565b6060600080600080610cd4611cc2565b6002878154811061080b57fe5b60018181548110610bcf57fe5b610cf6611371565b15610d0357610d0361138a565b3360009081526006602052604090205480610d1d57600080fd5b6005546001805463ffffffff909216916000198401908110610d3b57fe5b9060005260206000209060050201600201541415610d5857600080fd5b600180820381548110610d6757fe5b6000918252602090912060059091020160040154600160201b900463ffffffff16158015610dd257506005546001805463ffffffff909216916000198401908110610dae57fe5b6000918252602090912060059091020160040154600160201b900463ffffffff1614155b610ddb57600080fd5b6005546001805463ffffffff909216916000198401908110610df957fe5b600091825260208220600260059092020101919091555b8251811015610f3257600060066000858481518110610e2b57fe5b60200260200101516001600160a01b03166001600160a01b0316815260200190815260200160002054905080600014610f29576000600180830381548110610e6f57fe5b90600052602060002090600502019050600560009054906101000a900463ffffffff1663ffffffff16816003015414610ece5760055463ffffffff16600382015560018101805467ff000000000000001916600160381b179055610efc565b6001808201805460ff600160381b80830482169094011690920267ff00000000000000199092169190911790555b600354600182015460ff600160381b9091041661ffff9091161415610f2757610f27600183036113cf565b505b50600101610e10565b5060005b8351811015611243576000848281518110610f4d57fe5b6020908102919091018101516001600160a01b03811660009081526007909252604090912054909150801561123957600060026001830381548110610f8e57fe5b6000918252602091829020600590910201805460408051601f600260001961010060018716150201909416939093049283018590048502810185019091528181529193506110349284919083018282801561102a5780601f10610fff5761010080835404028352916020019161102a565b820191906000526020600020905b81548152906001019060200180831161100d57829003601f168201915b50505050506107dc565b6001600160a01b0316836001600160a01b03161461105157600080fd5b600554600382015463ffffffff909116146110915760055463ffffffff16600382015560018101805466ff0000000000001916600160301b1790556110be565b6001808201805460ff600160301b80830482169094011690920266ff000000000000199092169190911790555b600354600182015460ff600160301b9091041661ffff9091161415611237576110e5611cc2565b600260018403815481106110f557fe5b600091825260209182902060408051600593909302909101805460026001821615610100026000190190911604601f8101859004909402830161014090810190925261012083018481529293909284929091849184018282801561119a5780601f1061116f5761010080835404028352916020019161119a565b820191906000526020600020905b81548152906001019060200180831161117d57829003601f168201915b5050509183525050600182015463ffffffff8082166020840152600160201b80830461ffff166040850152600160301b830460ff9081166060860152600160381b9093049092166080840152600284015460a0840152600384015460c084015260049093015480841660e08401520482166101009182015260055490911690820152905061122b60001984016117b6565b6112358482611b80565b505b505b5050600101610f36565b50505050565b60055463ffffffff1681565b6000546001600160a01b0316331461126c57600080fd5b6000611277846107dc565b6001600160a01b0381166000908152600660205260409020549091501580156112b657506001600160a01b038116600090815260076020526040902054155b6112bf57600080fd5b6003546002546001546201000090920461ffff169101106112df57600080fd5b6112e7611cc2565b50604080516101208101825285815263ffffffff808616602083015261ffff8516928201929092526000606082018190526080820181905260a0820181905260c082015260055490911660e082018190526101008201526113488282611b80565b60015461135490611cae565b6003805461ffff191661ffff929092169190911790555050505050565b600354600454600160201b90910461ffff160143101590565b60015461139690611cae565b6003805461ffff191661ffff929092169190911790556005805463ffffffff19811663ffffffff91821660010190911617905543600455565b60015481106113dd57600080fd5b6113e5611cc2565b600182815481106113f257fe5b600091825260209182902060408051600593909302909101805460026001821615610100026000190190911604601f810185900490940283016101409081019092526101208301848152929390928492909184918401828280156114975780601f1061146c57610100808354040283529160200191611497565b820191906000526020600020905b81548152906001019060200180831161147a57829003601f168201915b5050509183525050600182015463ffffffff8082166020840152600160201b80830461ffff166040850152600160301b830460ff9081166060860152600160381b9093049092166080840152600284015460a0840152600384015460c084015260049093015480841660e0840152049091166101009091015280519091506000906006908290611526906107dc565b6001600160a01b0316815260208101919091526040016000205560018054600019810190811061155257fe5b90600052602060002090600502016001838154811061156d57fe5b9060005260206000209060050201600082018160000190805460018160011615610100020316600290046115a2929190611d8c565b5060018281018054838301805463ffffffff92831663ffffffff1991821617808355845465ffff0000000019909116600160201b9182900461ffff16820217808455855466ff00000000000019909116600160301b9182900460ff90811690920217808555955467ff0000000000000019909616600160381b96879004909116909502949094179091556002808701549086015560038087015490860155600495860180549690950180549683169690911695909517808655935467ffffffff00000000199094169382900416029190911790915580548061168057fe5b600082815260208120600019909201916005830201906116a08282611e01565b506001818101805467ffffffffffffffff1990811690915560006002840181905560038401556004909201805490921690915591555482146117b2576060600183815481106116eb57fe5b6000918252602091829020600590910201805460408051601f600260001961010060018716150201909416939093049283018590048502810185019091528181529283018282801561177e5780601f106117535761010080835404028352916020019161177e565b820191906000526020600020905b81548152906001019060200180831161176157829003601f168201915b505050505090508260010160066000611796846107dc565b6001600160a01b03168152602081019190915260400160002055505b5050565b60025481106117c457600080fd5b6117cc611cc2565b600282815481106117d957fe5b600091825260209182902060408051600593909302909101805460026001821615610100026000190190911604601f8101859004909402830161014090810190925261012083018481529293909284929091849184018282801561187e5780601f106118535761010080835404028352916020019161187e565b820191906000526020600020905b81548152906001019060200180831161186157829003601f168201915b5050509183525050600182015463ffffffff8082166020840152600160201b80830461ffff166040850152600160301b830460ff9081166060860152600160381b9093049092166080840152600284015460a0840152600384015460c084015260049093015480841660e084015204909116610100909101528051909150600090600790829061190d906107dc565b6001600160a01b0316815260208101919091526040016000205560028054600019810190811061193957fe5b90600052602060002090600502016002838154811061195457fe5b906000526020600020906005020160008201816000019080546001816001161561010002031660029004611989929190611d8c565b5060018281018054918301805463ffffffff93841663ffffffff1991821617808355835465ffff0000000019909116600160201b9182900461ffff16820217808455845466ff00000000000019909116600160301b9182900460ff90811690920217808555945467ff0000000000000019909516600160381b95869004909116909402939093179091556002808601548186015560038087015490860155600495860180549690950180549685169690921695909517808255935467ffffffff00000000199094169382900490921602919091179055805480611a6857fe5b60008281526020812060001990920191600583020190611a888282611e01565b5060018101805467ffffffffffffffff1990811690915560006002808401829055600384019190915560049092018054909116905591555482146117b257606060028381548110611ad557fe5b6000918252602091829020600590910201805460408051601f6002600019610100600187161502019094169390930492830185900485028101850190915281815292830182828015611b685780601f10611b3d57610100808354040283529160200191611b68565b820191906000526020600020905b815481529060010190602001808311611b4b57829003601f168201915b505050505090508260010160076000611796846107dc565b600180548082018083556000929092528251805184926005027fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf60191611bcb91839160200190611d0e565b5060208281015160018381018054604080880151606089015160808a015163ffffffff1994851663ffffffff9889161765ffff000000001916600160201b61ffff90941684021766ff0000000000001916600160301b60ff938416021767ff000000000000001916600160381b92909116919091021790935560a0880151600288015560c0880151600388015560e08801516004909701805461010090990151989092169685169690961767ffffffff000000001916969093160294909417905591546001600160a01b0395909516600090815260069092529020929092555050565b6000600261ffff8316046001019050919050565b6040805161012081018252606080825260006020830181905292820183905281018290526080810182905260a0810182905260c0810182905260e0810182905261010081019190915290565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10611d4f57805160ff1916838001178555611d7c565b82800160010185558215611d7c579182015b82811115611d7c578251825591602001919060010190611d61565b50611d88929150611e48565b5090565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10611dc55780548555611d7c565b82800160010185558215611d7c57600052602060002091601f016020900482015b82811115611d7c578254825591600101919060010190611de6565b50805460018160011615610100020316600290046000825580601f10611e275750611e45565b601f016020900490600052602060002090810190611e459190611e48565b50565b6107d991905b80821115611d885760008155600101611e4e56fea165627a7a72305820d86f2f26f79475dfc2993934f6e720204c7d9b84299fa64ad2b339cabd00e94a0029` // DeployNodesV2 deploys a new Ethereum contract, binding an instance of NodesV2 to it. -func DeployNodesV2(auth *bind.TransactOpts, backend bind.ContractBackend, _blockPerSession *big.Int) (common.Address, *types.Transaction, *NodesV2, error) { +func DeployNodesV2(auth *bind.TransactOpts, backend bind.ContractBackend, _blockPerSession uint16) (common.Address, *types.Transaction, *NodesV2, error) { parsed, err := abi.JSON(strings.NewReader(NodesV2ABI)) if err != nil { return common.Address{}, nil, nil, err @@ -216,7 +216,7 @@ func (_NodesV2 *NodesV2CallerSession) ActiveNodeCount() (*big.Int, error) { // ActiveNodes is a free data retrieval call binding the contract method 0x96f9d983. // -// Solidity: function activeNodes(uint256 ) constant returns(bytes publicKey, uint32 ip, uint16 port, uint8 joinVotes, uint8 removeVotes, uint256 lastTimeHasVoted, uint256 lastTimeHasBeenVoted) +// Solidity: function activeNodes(uint256 ) constant returns(bytes publicKey, uint32 ip, uint16 port, uint8 joinVotes, uint8 removeVotes, uint256 lastTimeHasVoted, uint256 lastTimeHasBeenVoted, uint32 joiningSession, uint32 activeSession) func (_NodesV2 *NodesV2Caller) ActiveNodes(opts *bind.CallOpts, arg0 *big.Int) (struct { PublicKey []byte Ip uint32 @@ -225,6 +225,8 @@ func (_NodesV2 *NodesV2Caller) ActiveNodes(opts *bind.CallOpts, arg0 *big.Int) ( RemoveVotes uint8 LastTimeHasVoted *big.Int LastTimeHasBeenVoted *big.Int + JoiningSession uint32 + ActiveSession uint32 }, error) { ret := new(struct { PublicKey []byte @@ -234,6 +236,8 @@ func (_NodesV2 *NodesV2Caller) ActiveNodes(opts *bind.CallOpts, arg0 *big.Int) ( RemoveVotes uint8 LastTimeHasVoted *big.Int LastTimeHasBeenVoted *big.Int + JoiningSession uint32 + ActiveSession uint32 }) out := ret err := _NodesV2.contract.Call(opts, out, "activeNodes", arg0) @@ -242,7 +246,7 @@ func (_NodesV2 *NodesV2Caller) ActiveNodes(opts *bind.CallOpts, arg0 *big.Int) ( // ActiveNodes is a free data retrieval call binding the contract method 0x96f9d983. // -// Solidity: function activeNodes(uint256 ) constant returns(bytes publicKey, uint32 ip, uint16 port, uint8 joinVotes, uint8 removeVotes, uint256 lastTimeHasVoted, uint256 lastTimeHasBeenVoted) +// Solidity: function activeNodes(uint256 ) constant returns(bytes publicKey, uint32 ip, uint16 port, uint8 joinVotes, uint8 removeVotes, uint256 lastTimeHasVoted, uint256 lastTimeHasBeenVoted, uint32 joiningSession, uint32 activeSession) func (_NodesV2 *NodesV2Session) ActiveNodes(arg0 *big.Int) (struct { PublicKey []byte Ip uint32 @@ -251,13 +255,15 @@ func (_NodesV2 *NodesV2Session) ActiveNodes(arg0 *big.Int) (struct { RemoveVotes uint8 LastTimeHasVoted *big.Int LastTimeHasBeenVoted *big.Int + JoiningSession uint32 + ActiveSession uint32 }, error) { return _NodesV2.Contract.ActiveNodes(&_NodesV2.CallOpts, arg0) } // ActiveNodes is a free data retrieval call binding the contract method 0x96f9d983. // -// Solidity: function activeNodes(uint256 ) constant returns(bytes publicKey, uint32 ip, uint16 port, uint8 joinVotes, uint8 removeVotes, uint256 lastTimeHasVoted, uint256 lastTimeHasBeenVoted) +// Solidity: function activeNodes(uint256 ) constant returns(bytes publicKey, uint32 ip, uint16 port, uint8 joinVotes, uint8 removeVotes, uint256 lastTimeHasVoted, uint256 lastTimeHasBeenVoted, uint32 joiningSession, uint32 activeSession) func (_NodesV2 *NodesV2CallerSession) ActiveNodes(arg0 *big.Int) (struct { PublicKey []byte Ip uint32 @@ -266,16 +272,18 @@ func (_NodesV2 *NodesV2CallerSession) ActiveNodes(arg0 *big.Int) (struct { RemoveVotes uint8 LastTimeHasVoted *big.Int LastTimeHasBeenVoted *big.Int + JoiningSession uint32 + ActiveSession uint32 }, error) { return _NodesV2.Contract.ActiveNodes(&_NodesV2.CallOpts, arg0) } // CurrentSession is a free data retrieval call binding the contract method 0xd4166763. // -// Solidity: function currentSession() constant returns(uint256) -func (_NodesV2 *NodesV2Caller) CurrentSession(opts *bind.CallOpts) (*big.Int, error) { +// Solidity: function currentSession() constant returns(uint32) +func (_NodesV2 *NodesV2Caller) CurrentSession(opts *bind.CallOpts) (uint32, error) { var ( - ret0 = new(*big.Int) + ret0 = new(uint32) ) out := ret0 err := _NodesV2.contract.Call(opts, out, "currentSession") @@ -284,15 +292,15 @@ func (_NodesV2 *NodesV2Caller) CurrentSession(opts *bind.CallOpts) (*big.Int, er // CurrentSession is a free data retrieval call binding the contract method 0xd4166763. // -// Solidity: function currentSession() constant returns(uint256) -func (_NodesV2 *NodesV2Session) CurrentSession() (*big.Int, error) { +// Solidity: function currentSession() constant returns(uint32) +func (_NodesV2 *NodesV2Session) CurrentSession() (uint32, error) { return _NodesV2.Contract.CurrentSession(&_NodesV2.CallOpts) } // CurrentSession is a free data retrieval call binding the contract method 0xd4166763. // -// Solidity: function currentSession() constant returns(uint256) -func (_NodesV2 *NodesV2CallerSession) CurrentSession() (*big.Int, error) { +// Solidity: function currentSession() constant returns(uint32) +func (_NodesV2 *NodesV2CallerSession) CurrentSession() (uint32, error) { return _NodesV2.Contract.CurrentSession(&_NodesV2.CallOpts) } @@ -324,65 +332,73 @@ func (_NodesV2 *NodesV2CallerSession) GetCurrentSession() (*big.Int, error) { // GetInactiveNode is a free data retrieval call binding the contract method 0x93696e1a. // -// Solidity: function getInactiveNode(uint256 index) constant returns(bytes, uint32, uint16) -func (_NodesV2 *NodesV2Caller) GetInactiveNode(opts *bind.CallOpts, index *big.Int) ([]byte, uint32, uint16, error) { +// Solidity: function getInactiveNode(uint256 index) constant returns(bytes, uint32, uint16, uint32, uint32) +func (_NodesV2 *NodesV2Caller) GetInactiveNode(opts *bind.CallOpts, index *big.Int) ([]byte, uint32, uint16, uint32, uint32, error) { var ( ret0 = new([]byte) ret1 = new(uint32) ret2 = new(uint16) + ret3 = new(uint32) + ret4 = new(uint32) ) out := &[]interface{}{ ret0, ret1, ret2, + ret3, + ret4, } err := _NodesV2.contract.Call(opts, out, "getInactiveNode", index) - return *ret0, *ret1, *ret2, err + return *ret0, *ret1, *ret2, *ret3, *ret4, err } // GetInactiveNode is a free data retrieval call binding the contract method 0x93696e1a. // -// Solidity: function getInactiveNode(uint256 index) constant returns(bytes, uint32, uint16) -func (_NodesV2 *NodesV2Session) GetInactiveNode(index *big.Int) ([]byte, uint32, uint16, error) { +// Solidity: function getInactiveNode(uint256 index) constant returns(bytes, uint32, uint16, uint32, uint32) +func (_NodesV2 *NodesV2Session) GetInactiveNode(index *big.Int) ([]byte, uint32, uint16, uint32, uint32, error) { return _NodesV2.Contract.GetInactiveNode(&_NodesV2.CallOpts, index) } // GetInactiveNode is a free data retrieval call binding the contract method 0x93696e1a. // -// Solidity: function getInactiveNode(uint256 index) constant returns(bytes, uint32, uint16) -func (_NodesV2 *NodesV2CallerSession) GetInactiveNode(index *big.Int) ([]byte, uint32, uint16, error) { +// Solidity: function getInactiveNode(uint256 index) constant returns(bytes, uint32, uint16, uint32, uint32) +func (_NodesV2 *NodesV2CallerSession) GetInactiveNode(index *big.Int) ([]byte, uint32, uint16, uint32, uint32, error) { return _NodesV2.Contract.GetInactiveNode(&_NodesV2.CallOpts, index) } // GetNode is a free data retrieval call binding the contract method 0x4f0f4aa9. // -// Solidity: function getNode(uint256 index) constant returns(bytes, uint32, uint16) -func (_NodesV2 *NodesV2Caller) GetNode(opts *bind.CallOpts, index *big.Int) ([]byte, uint32, uint16, error) { +// Solidity: function getNode(uint256 index) constant returns(bytes, uint32, uint16, uint32, uint32) +func (_NodesV2 *NodesV2Caller) GetNode(opts *bind.CallOpts, index *big.Int) ([]byte, uint32, uint16, uint32, uint32, error) { var ( ret0 = new([]byte) ret1 = new(uint32) ret2 = new(uint16) + ret3 = new(uint32) + ret4 = new(uint32) ) out := &[]interface{}{ ret0, ret1, ret2, + ret3, + ret4, } err := _NodesV2.contract.Call(opts, out, "getNode", index) - return *ret0, *ret1, *ret2, err + return *ret0, *ret1, *ret2, *ret3, *ret4, err } // GetNode is a free data retrieval call binding the contract method 0x4f0f4aa9. // -// Solidity: function getNode(uint256 index) constant returns(bytes, uint32, uint16) -func (_NodesV2 *NodesV2Session) GetNode(index *big.Int) ([]byte, uint32, uint16, error) { +// Solidity: function getNode(uint256 index) constant returns(bytes, uint32, uint16, uint32, uint32) +func (_NodesV2 *NodesV2Session) GetNode(index *big.Int) ([]byte, uint32, uint16, uint32, uint32, error) { return _NodesV2.Contract.GetNode(&_NodesV2.CallOpts, index) } // GetNode is a free data retrieval call binding the contract method 0x4f0f4aa9. // -// Solidity: function getNode(uint256 index) constant returns(bytes, uint32, uint16) -func (_NodesV2 *NodesV2CallerSession) GetNode(index *big.Int) ([]byte, uint32, uint16, error) { +// Solidity: function getNode(uint256 index) constant returns(bytes, uint32, uint16, uint32, uint32) +func (_NodesV2 *NodesV2CallerSession) GetNode(index *big.Int) ([]byte, uint32, uint16, uint32, uint32, error) { return _NodesV2.Contract.GetNode(&_NodesV2.CallOpts, index) } @@ -414,7 +430,7 @@ func (_NodesV2 *NodesV2CallerSession) InactiveNodeCount() (*big.Int, error) { // InactiveNodes is a free data retrieval call binding the contract method 0x72460fa8. // -// Solidity: function inactiveNodes(uint256 ) constant returns(bytes publicKey, uint32 ip, uint16 port, uint8 joinVotes, uint8 removeVotes, uint256 lastTimeHasVoted, uint256 lastTimeHasBeenVoted) +// Solidity: function inactiveNodes(uint256 ) constant returns(bytes publicKey, uint32 ip, uint16 port, uint8 joinVotes, uint8 removeVotes, uint256 lastTimeHasVoted, uint256 lastTimeHasBeenVoted, uint32 joiningSession, uint32 activeSession) func (_NodesV2 *NodesV2Caller) InactiveNodes(opts *bind.CallOpts, arg0 *big.Int) (struct { PublicKey []byte Ip uint32 @@ -423,6 +439,8 @@ func (_NodesV2 *NodesV2Caller) InactiveNodes(opts *bind.CallOpts, arg0 *big.Int) RemoveVotes uint8 LastTimeHasVoted *big.Int LastTimeHasBeenVoted *big.Int + JoiningSession uint32 + ActiveSession uint32 }, error) { ret := new(struct { PublicKey []byte @@ -432,6 +450,8 @@ func (_NodesV2 *NodesV2Caller) InactiveNodes(opts *bind.CallOpts, arg0 *big.Int) RemoveVotes uint8 LastTimeHasVoted *big.Int LastTimeHasBeenVoted *big.Int + JoiningSession uint32 + ActiveSession uint32 }) out := ret err := _NodesV2.contract.Call(opts, out, "inactiveNodes", arg0) @@ -440,7 +460,7 @@ func (_NodesV2 *NodesV2Caller) InactiveNodes(opts *bind.CallOpts, arg0 *big.Int) // InactiveNodes is a free data retrieval call binding the contract method 0x72460fa8. // -// Solidity: function inactiveNodes(uint256 ) constant returns(bytes publicKey, uint32 ip, uint16 port, uint8 joinVotes, uint8 removeVotes, uint256 lastTimeHasVoted, uint256 lastTimeHasBeenVoted) +// Solidity: function inactiveNodes(uint256 ) constant returns(bytes publicKey, uint32 ip, uint16 port, uint8 joinVotes, uint8 removeVotes, uint256 lastTimeHasVoted, uint256 lastTimeHasBeenVoted, uint32 joiningSession, uint32 activeSession) func (_NodesV2 *NodesV2Session) InactiveNodes(arg0 *big.Int) (struct { PublicKey []byte Ip uint32 @@ -449,13 +469,15 @@ func (_NodesV2 *NodesV2Session) InactiveNodes(arg0 *big.Int) (struct { RemoveVotes uint8 LastTimeHasVoted *big.Int LastTimeHasBeenVoted *big.Int + JoiningSession uint32 + ActiveSession uint32 }, error) { return _NodesV2.Contract.InactiveNodes(&_NodesV2.CallOpts, arg0) } // InactiveNodes is a free data retrieval call binding the contract method 0x72460fa8. // -// Solidity: function inactiveNodes(uint256 ) constant returns(bytes publicKey, uint32 ip, uint16 port, uint8 joinVotes, uint8 removeVotes, uint256 lastTimeHasVoted, uint256 lastTimeHasBeenVoted) +// Solidity: function inactiveNodes(uint256 ) constant returns(bytes publicKey, uint32 ip, uint16 port, uint8 joinVotes, uint8 removeVotes, uint256 lastTimeHasVoted, uint256 lastTimeHasBeenVoted, uint32 joiningSession, uint32 activeSession) func (_NodesV2 *NodesV2CallerSession) InactiveNodes(arg0 *big.Int) (struct { PublicKey []byte Ip uint32 @@ -464,6 +486,8 @@ func (_NodesV2 *NodesV2CallerSession) InactiveNodes(arg0 *big.Int) (struct { RemoveVotes uint8 LastTimeHasVoted *big.Int LastTimeHasBeenVoted *big.Int + JoiningSession uint32 + ActiveSession uint32 }, error) { return _NodesV2.Contract.InactiveNodes(&_NodesV2.CallOpts, arg0) } diff --git a/test/TestNodesV2.js b/test/TestNodesV2.js index 8fa3b50..3f664d2 100644 --- a/test/TestNodesV2.js +++ b/test/TestNodesV2.js @@ -185,10 +185,10 @@ contract('Nodes', async (accounts) => { }); }); - xdescribe('voter is newly active', async () => { + describe('voter is newly active', async () => { it('throws an exception', async () => { try { - await instance.vote([node4.address], [node2.address], { from: accounts[3] }); + await instance.vote([node4.address], [node2.address], { from: accounts[4] }); } catch (error) { return; } @@ -218,6 +218,7 @@ contract('Nodes', async (accounts) => { assert.equal(inactiveNode1[0], node4.pk); assert.equal(inactiveNode1[1], node4.ip); assert.equal(inactiveNode1[2], node4.port); + assert.equal(inactiveNode1[3], 0); }); it('removes nodes that have failed the checks and promotes those that have passed them', async () => { @@ -233,16 +234,22 @@ contract('Nodes', async (accounts) => { pk: actualNode1[0], ip: actualNode1[1], port: actualNode1[2], + joiningSession: actualNode1[3], + activeSession: actualNode1[4], }, { pk: actualNode2[0], ip: actualNode2[1], port: actualNode2[2], + joiningSession: actualNode2[3], + activeSession: actualNode2[4], }, { pk: actualNode3[0], ip: actualNode3[1], port: actualNode3[2], + joiningSession: actualNode3[3], + activeSession: actualNode3[4], }, ]; @@ -251,15 +258,66 @@ contract('Nodes', async (accounts) => { assert.equal(actualNodes[0].pk, node3.pk); assert.equal(actualNodes[0].port, node3.port); assert.equal(actualNodes[0].ip, node3.ip); + assert.equal(actualNodes[0].joiningSession, 0); + assert.equal(actualNodes[0].activeSession, 0); assert.equal(actualNodes[1].pk, node1.pk); assert.equal(actualNodes[1].port, node1.port); assert.equal(actualNodes[1].ip, node1.ip); - + assert.equal(actualNodes[1].joiningSession, 0); + assert.equal(actualNodes[1].activeSession, 0); assert.equal(actualNodes[2].pk, node5.pk); assert.equal(actualNodes[2].port, node5.port); assert.equal(actualNodes[2].ip, node5.ip); + assert.equal(actualNodes[2].joiningSession, 0); + assert.equal(actualNodes[2].activeSession, 1); + }); + + describe('a node removed re-register', async () => { + beforeEach(async () => { + await instance.registerNode(node2.pk, node2.ip, node2.port, { from: accounts[1] }); + }); + + it('adds the node', async () => { + const actualNodeCount = await instance.inactiveNodeCount(); + assert.equal(2, actualNodeCount); + }); + + it('adds the node', async () => { + const actualNode1 = await instance.getInactiveNode(0); + const actualNode2 = await instance.getInactiveNode(1); + const actualNodes = [ + { + pk: actualNode1[0], + ip: actualNode1[1], + port: actualNode1[2], + joiningSession: actualNode1[3], + activeSession: actualNode1[4], + }, + { + pk: actualNode2[0], + ip: actualNode2[1], + port: actualNode2[2], + joiningSession: actualNode2[3], + activeSession: actualNode2[4], + }, + ]; + + actualNodes.sort(compareNodes); + + assert.equal(actualNodes[0].pk, node4.pk); + assert.equal(actualNodes[0].port, node4.port); + assert.equal(actualNodes[0].ip, node4.ip); + assert.equal(actualNodes[0].joiningSession, 0); + assert.equal(actualNodes[0].activeSession, 0); + + assert.equal(actualNodes[1].pk, node2.pk); + assert.equal(actualNodes[1].port, node2.port); + assert.equal(actualNodes[1].ip, node2.ip); + assert.equal(actualNodes[1].joiningSession, 2); + assert.equal(actualNodes[1].activeSession, 0); + }); }); }); });