From ad66858ac1028786f90808ab26b3ba1c02b081b1 Mon Sep 17 00:00:00 2001 From: rjl493456442 Date: Thu, 25 Apr 2019 19:21:21 +0800 Subject: [PATCH] cmd, contracts, les: discard stale checkpoint --- cmd/registrar/query.go | 19 ++------ contracts/registrar/contract/registrar.go | 34 +------------- contracts/registrar/contract/registrar.sol | 54 ++++++++-------------- les/registrar.go | 26 +++++------ 4 files changed, 39 insertions(+), 94 deletions(-) diff --git a/cmd/registrar/query.go b/cmd/registrar/query.go index d092f30998..5a8ee33b28 100644 --- a/cmd/registrar/query.go +++ b/cmd/registrar/query.go @@ -19,7 +19,6 @@ package main import ( "errors" "fmt" - "math/big" "github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/common" @@ -46,7 +45,6 @@ var commandQueryCheckpoint = cli.Command{ Fetch the registered checkpoint with the specified index. `, Flags: []cli.Flag{ - checkpointIndexFlag, clientURLFlag, }, Action: utils.MigrateFlags(queryCheckpoint), @@ -84,20 +82,11 @@ func queryAdmin(ctx *cli.Context) error { // registrar contract. func queryCheckpoint(ctx *cli.Context) error { contract := setupContract(setupDialContext(ctx)) - if ctx.GlobalIsSet(checkpointIndexFlag.Name) { - index := ctx.GlobalInt64(checkpointIndexFlag.Name) - checkpoint, height, err := contract.Contract().GetCheckpoint(nil, big.NewInt(index)) - if err != nil { - return err - } - fmt.Printf("Checkpoint(registered at height #%d) %d => %s\n", height, index, common.Hash(checkpoint).Hex()) - } else { - index, checkpoint, height, err := contract.Contract().GetLatestCheckpoint(nil) - if err != nil { - return err - } - fmt.Printf("Latest checkpoint(registered at height #%d) %d => %s\n", height, index, common.Hash(checkpoint).Hex()) + index, checkpoint, height, err := contract.Contract().GetLatestCheckpoint(nil) + if err != nil { + return err } + fmt.Printf("Latest checkpoint(registered at height #%d) %d => %s\n", height, index, common.Hash(checkpoint).Hex()) return nil } diff --git a/contracts/registrar/contract/registrar.go b/contracts/registrar/contract/registrar.go index 6710d4b371..2583ade8d9 100644 --- a/contracts/registrar/contract/registrar.go +++ b/contracts/registrar/contract/registrar.go @@ -28,10 +28,10 @@ var ( ) // ContractABI is the input ABI used to generate the binding from. -const ContractABI = "[{\"constant\":true,\"inputs\":[],\"name\":\"GetAllAdmin\",\"outputs\":[{\"name\":\"\",\"type\":\"address[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"GetLatestCheckpoint\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"},{\"name\":\"\",\"type\":\"bytes32\"},{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_sectionIndex\",\"type\":\"uint256\"}],\"name\":\"GetCheckpoint\",\"outputs\":[{\"name\":\"\",\"type\":\"bytes32\"},{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_sectionIndex\",\"type\":\"uint256\"},{\"name\":\"_hash\",\"type\":\"bytes32\"},{\"name\":\"_sig\",\"type\":\"bytes\"}],\"name\":\"SetCheckpoint\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"GetPending\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"},{\"name\":\"\",\"type\":\"address[]\"},{\"name\":\"\",\"type\":\"bytes32[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"_adminlist\",\"type\":\"address[]\"},{\"name\":\"_sectionSize\",\"type\":\"uint256\"},{\"name\":\"_processConfirms\",\"type\":\"uint256\"},{\"name\":\"_threshold\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"index\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"checkpointHash\",\"type\":\"bytes32\"},{\"indexed\":false,\"name\":\"signature\",\"type\":\"bytes\"}],\"name\":\"NewCheckpointEvent\",\"type\":\"event\"}]" +const ContractABI = "[{\"constant\":true,\"inputs\":[],\"name\":\"GetAllAdmin\",\"outputs\":[{\"name\":\"\",\"type\":\"address[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"GetLatestCheckpoint\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"},{\"name\":\"\",\"type\":\"bytes32\"},{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_sectionIndex\",\"type\":\"uint256\"},{\"name\":\"_hash\",\"type\":\"bytes32\"},{\"name\":\"_sig\",\"type\":\"bytes\"}],\"name\":\"SetCheckpoint\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"GetPending\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"},{\"name\":\"\",\"type\":\"address[]\"},{\"name\":\"\",\"type\":\"bytes32[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"_adminlist\",\"type\":\"address[]\"},{\"name\":\"_sectionSize\",\"type\":\"uint256\"},{\"name\":\"_processConfirms\",\"type\":\"uint256\"},{\"name\":\"_threshold\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"index\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"checkpointHash\",\"type\":\"bytes32\"},{\"indexed\":false,\"name\":\"signature\",\"type\":\"bytes\"}],\"name\":\"NewCheckpointEvent\",\"type\":\"event\"}]" // ContractBin is the compiled bytecode used for deploying new contracts. -const ContractBin = `608060405234801561001057600080fd5b5060405161133d38038061133d8339810180604052608081101561003357600080fd5b81019080805164010000000081111561004b57600080fd5b8281019050602081018481111561006157600080fd5b815185602082028301116401000000008211171561007e57600080fd5b505092919060200180519060200190929190805190602001909291908051906020019092919050505060008090505b84518110156101af5760016004600087848151811015156100ca57fe5b9060200190602002015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055506005858281518110151561013557fe5b9060200190602002015190806001815401808255809150509060018203906000526020600020016000909192909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505080806001019150506100ad565b508260098190555081600a8190555080600b8190555050505050611165806101d86000396000f3fe608060405234801561001057600080fd5b5060043610610074576000357c01000000000000000000000000000000000000000000000000000000009004806345848dfc146100795780634d6a304c146100d8578063710aeac8146101045780639475a2b91461014d578063fff5f36714610234575b600080fd5b6100816102e2565b6040518080602001828103825283818151815260200191508051906020019060200280838360005b838110156100c45780820151818401526020810190506100a9565b505050509050019250505060405180910390f35b6100e06103c8565b60405180848152602001838152602001828152602001935050505060405180910390f35b6101306004803603602081101561011a57600080fd5b81019080803590602001909291905050506103f1565b604051808381526020018281526020019250505060405180910390f35b61021a6004803603606081101561016357600080fd5b8101908080359060200190929190803590602001909291908035906020019064010000000081111561019457600080fd5b8201836020820111156101a657600080fd5b803590602001918460018302840111640100000000831117156101c857600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050610425565b604051808215151515815260200191505060405180910390f35b61023c610bd1565b604051808481526020018060200180602001838103835285818151815260200191508051906020019060200280838360005b8381101561028957808201518184015260208101905061026e565b50505050905001838103825284818151815260200191508051906020019060200280838360005b838110156102cb5780820151818401526020810190506102b0565b505050509050019550505050505060405180910390f35b6060806005805490506040519080825280602002602001820160405280156103195781602001602082028038833980820191505090505b50905060008090505b6005805490508110156103c05760058181548110151561033e57fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16828281518110151561037757fe5b9060200190602002019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff16815250508080600101915050610322565b508091505090565b60008060008060006103db6007546103f1565b9150915060075482829450945094505050909192565b6000806006600084815260200190815260200160002054600860008581526020019081526020016000205491509150915091565b6000600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16151561047f57600080fd5b600a5460095460018601020143108061049f575060095460028501024310155b156104ad5760009050610bca565b600754841480156104e0575060006007541415806104df57506000600860008081526020019081526020016000205414155b5b156104ee5760009050610bca565b60008314806104fe575060008251145b1561050c5760009050610bca565b83600080015414151561052257610521610db5565b5b60008060020160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205490508381141561057a576000915050610bca565b6000808214905084600060020160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508015156108a2576000806003016000848152602001908152602001600020905060008090505b6001828054905003811015610753573373ffffffffffffffffffffffffffffffffffffffff16828281548110151561062257fe5b906000526020600020906002020160000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614156107465781600183805490500381548110151561068557fe5b906000526020600020906002020182828154811015156106a157fe5b90600052602060002090600202016000820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168160000160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506001820181600101908054600181600116156101000203166002900461073d929190610f19565b50905050610753565b80806001019150506105ee565b5080600182805490500381548110151561076957fe5b9060005260206000209060020201600080820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556001820160006107af9190610fa0565b5050600181818180549050039150816107c89190610fe8565b506000600301600087815260200190815260200160002060408051908101604052803373ffffffffffffffffffffffffffffffffffffffff168152602001878152509080600181540180825580915050906001820390600052602060002090600202016000909192909190915060008201518160000160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550602082015181600101908051906020019061089892919061101a565b5050505050610993565b60016000600101600082825401925050819055508560008001819055506000600301600086815260200190815260200160002060408051908101604052803373ffffffffffffffffffffffffffffffffffffffff168152602001868152509080600181540180825580915050906001820390600052602060002090600202016000909192909190915060008201518160000160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550602082015181600101908051906020019061098e92919061101a565b505050505b600b54600060030160008781526020019081526020016000208054905010156109c157600192505050610bca565b84600660008881526020019081526020016000208190555043600860008881526020019081526020016000208190555085600781905550606060008090505b600b54811015610b1457816000600301600089815260200190815260200160002082815481101515610a2e57fe5b90600052602060002090600202016001016040516020018083805190602001908083835b602083101515610a775780518252602082019150602081019050602083039250610a52565b6001836020036101000a03801982511681845116808217855250505050505090500182805460018160011615610100020316600290048015610af05780601f10610ace576101008083540402835291820191610af0565b820191906000526020600020905b815481529060010190602001808311610adc575b50509250505060405160208183030381529060405291508080600101915050610a00565b50867ff7aa4ddabff125da62b8692942a8dee5c673822157f230e5520a5b4e92d6929f87836040518083815260200180602001828103825283818151815260200191508051906020019080838360005b83811015610b7f578082015181840152602081019050610b64565b50505050905090810190601f168015610bac5780820380516001836020036101000a031916815260200191505b50935050505060405180910390a2610bc2610db5565b600193505050505b9392505050565b600060608060008090506060600060010154604051908082528060200260200182016040528015610c115781602001602082028038833980820191505090505b5090506060600060010154604051908082528060200260200182016040528015610c4a5781602001602082028038833980820191505090505b50905060008090505b600580549050811015610d9f576000806002016000600584815481101515610c7757fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050600081141515610d9157600582815481101515610cf857fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168486815181101515610d3157fe5b9060200190602002019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050808386815181101515610d7c57fe5b90602001906020020181815250506001850194505b508080600101915050610c53565b5060008001548282955095509550505050909192565b60008090505b600580549050811015610f01576000806002016000600584815481101515610ddf57fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050600081141515610ef357600060030160008281526020019081526020016000206000610e73919061109a565b60006002016000600584815481101515610e8957fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600090555b508080600101915050610dbb565b50600080600082016000905560018201600090555050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10610f525780548555610f8f565b82800160010185558215610f8f57600052602060002091601f016020900482015b82811115610f8e578254825591600101919060010190610f73565b5b509050610f9c91906110be565b5090565b50805460018160011615610100020316600290046000825580601f10610fc65750610fe5565b601f016020900490600052602060002090810190610fe491906110be565b5b50565b8154818355818111156110155760020281600202836000526020600020918201910161101491906110e3565b5b505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061105b57805160ff1916838001178555611089565b82800160010185558215611089579182015b8281111561108857825182559160200191906001019061106d565b5b50905061109691906110be565b5090565b50805460008255600202906000526020600020908101906110bb91906110e3565b50565b6110e091905b808211156110dc5760008160009055506001016110c4565b5090565b90565b61113691905b8082111561113257600080820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556001820160006111299190610fa0565b506002016110e9565b5090565b9056fea165627a7a72305820343743933f0f54f8f392dd1342af5845ad91c7463108664959aecfa5eb6e0ca00029` +const ContractBin = `608060405234801561001057600080fd5b506040516112713803806112718339810180604052608081101561003357600080fd5b81019080805164010000000081111561004b57600080fd5b8281019050602081018481111561006157600080fd5b815185602082028301116401000000008211171561007e57600080fd5b505092919060200180519060200190929190805190602001909291908051906020019092919050505060008090505b84518110156101af5760016004600087848151811015156100ca57fe5b9060200190602002015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055506005858281518110151561013557fe5b9060200190602002015190806001815401808255809150509060018203906000526020600020016000909192909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505080806001019150506100ad565b508260098190555081600a8190555080600b8190555050505050611099806101d86000396000f3fe608060405234801561001057600080fd5b5060043610610069576000357c01000000000000000000000000000000000000000000000000000000009004806345848dfc1461006e5780634d6a304c146100cd5780639475a2b9146100f9578063fff5f367146101e0575b600080fd5b61007661028e565b6040518080602001828103825283818151815260200191508051906020019060200280838360005b838110156100b957808201518184015260208101905061009e565b505050509050019250505060405180910390f35b6100d5610374565b60405180848152602001838152602001828152602001935050505060405180910390f35b6101c66004803603606081101561010f57600080fd5b8101908080359060200190929190803590602001909291908035906020019064010000000081111561014057600080fd5b82018360208201111561015257600080fd5b8035906020019184600183028401116401000000008311171561017457600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f82011690508083019250505050505050919291929050505061038d565b604051808215151515815260200191505060405180910390f35b6101e8610b05565b604051808481526020018060200180602001838103835285818151815260200191508051906020019060200280838360005b8381101561023557808201518184015260208101905061021a565b50505050905001838103825284818151815260200191508051906020019060200280838360005b8381101561027757808201518184015260208101905061025c565b505050509050019550505050505060405180910390f35b6060806005805490506040519080825280602002602001820160405280156102c55781602001602082028038833980820191505090505b50905060008090505b60058054905081101561036c576005818154811015156102ea57fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16828281518110151561032357fe5b9060200190602002019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff168152505080806001019150506102ce565b508091505090565b6000806000600654600854600754925092509250909192565b6000600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615156103e757600080fd5b600a54600954600186010201431080610407575060095460028501024310155b156104155760009050610afe565b60065484148015610437575060006006541415806104365750600060075414155b5b156104455760009050610afe565b6000831480610455575060008251145b156104635760009050610afe565b83600080015414151561047957610478610ce9565b5b60008060020160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050838114156104d1576000915050610afe565b6000808214905084600060020160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550801561061a5760016000600101600082825401925050819055508560008001819055506000600301600086815260200190815260200160002060408051908101604052803373ffffffffffffffffffffffffffffffffffffffff168152602001868152509080600181540180825580915050906001820390600052602060002090600202016000909192909190915060008201518160000160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506020820151816001019080519060200190610611929190610e4d565b505050506108e9565b6000806003016000848152602001908152602001600020905060008090505b600182805490500381101561079e573373ffffffffffffffffffffffffffffffffffffffff16828281548110151561066d57fe5b906000526020600020906002020160000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161415610791578160018380549050038154811015156106d057fe5b906000526020600020906002020182828154811015156106ec57fe5b90600052602060002090600202016000820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168160000160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060018201816001019080546001816001161561010002031660029004610788929190610ecd565b5090505061079e565b8080600101915050610639565b508060018280549050038154811015156107b457fe5b9060005260206000209060020201600080820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556001820160006107fa9190610f54565b5050600181818180549050039150816108139190610f9c565b506000600301600087815260200190815260200160002060408051908101604052803373ffffffffffffffffffffffffffffffffffffffff168152602001878152509080600181540180825580915050906001820390600052602060002090600202016000909192909190915060008201518160000160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060208201518160010190805190602001906108e3929190610e4d565b50505050505b600b546000600301600087815260200190815260200160002080549050101561091757600192505050610afe565b846008819055504360078190555085600681905550606060008090505b600b54811015610a485781600060030160008981526020019081526020016000208281548110151561096257fe5b90600052602060002090600202016001016040516020018083805190602001908083835b6020831015156109ab5780518252602082019150602081019050602083039250610986565b6001836020036101000a03801982511681845116808217855250505050505090500182805460018160011615610100020316600290048015610a245780601f10610a02576101008083540402835291820191610a24565b820191906000526020600020905b815481529060010190602001808311610a10575b50509250505060405160208183030381529060405291508080600101915050610934565b50867ff7aa4ddabff125da62b8692942a8dee5c673822157f230e5520a5b4e92d6929f87836040518083815260200180602001828103825283818151815260200191508051906020019080838360005b83811015610ab3578082015181840152602081019050610a98565b50505050905090810190601f168015610ae05780820380516001836020036101000a031916815260200191505b50935050505060405180910390a2610af6610ce9565b600193505050505b9392505050565b600060608060008090506060600060010154604051908082528060200260200182016040528015610b455781602001602082028038833980820191505090505b5090506060600060010154604051908082528060200260200182016040528015610b7e5781602001602082028038833980820191505090505b50905060008090505b600580549050811015610cd3576000806002016000600584815481101515610bab57fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050600081141515610cc557600582815481101515610c2c57fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168486815181101515610c6557fe5b9060200190602002019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050808386815181101515610cb057fe5b90602001906020020181815250506001850194505b508080600101915050610b87565b5060008001548282955095509550505050909192565b60008090505b600580549050811015610e35576000806002016000600584815481101515610d1357fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050600081141515610e2757600060030160008281526020019081526020016000206000610da79190610fce565b60006002016000600584815481101515610dbd57fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600090555b508080600101915050610cef565b50600080600082016000905560018201600090555050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10610e8e57805160ff1916838001178555610ebc565b82800160010185558215610ebc579182015b82811115610ebb578251825591602001919060010190610ea0565b5b509050610ec99190610ff2565b5090565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10610f065780548555610f43565b82800160010185558215610f4357600052602060002091601f016020900482015b82811115610f42578254825591600101919060010190610f27565b5b509050610f509190610ff2565b5090565b50805460018160011615610100020316600290046000825580601f10610f7a5750610f99565b601f016020900490600052602060002090810190610f989190610ff2565b5b50565b815481835581811115610fc957600202816002028360005260206000209182019101610fc89190611017565b5b505050565b5080546000825560020290600052602060002090810190610fef9190611017565b50565b61101491905b80821115611010576000816000905550600101610ff8565b5090565b90565b61106a91905b8082111561106657600080820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff021916905560018201600061105d9190610f54565b5060020161101d565b5090565b9056fea165627a7a723058203bfdb848520ad4b19738a6964aedf61ada0b07176b1503a8fe1cd3aaa704dd370029` // DeployContract deploys a new Ethereum contract, binding an instance of Contract to it. func DeployContract(auth *bind.TransactOpts, backend bind.ContractBackend, _adminlist []common.Address, _sectionSize *big.Int, _processConfirms *big.Int, _threshold *big.Int) (common.Address, *types.Transaction, *Contract, error) { @@ -214,36 +214,6 @@ func (_Contract *ContractCallerSession) GetAllAdmin() ([]common.Address, error) return _Contract.Contract.GetAllAdmin(&_Contract.CallOpts) } -// GetCheckpoint is a free data retrieval call binding the contract method 0x710aeac8. -// -// Solidity: function GetCheckpoint(uint256 _sectionIndex) constant returns(bytes32, uint256) -func (_Contract *ContractCaller) GetCheckpoint(opts *bind.CallOpts, _sectionIndex *big.Int) ([32]byte, *big.Int, error) { - var ( - ret0 = new([32]byte) - ret1 = new(*big.Int) - ) - out := &[]interface{}{ - ret0, - ret1, - } - err := _Contract.contract.Call(opts, out, "GetCheckpoint", _sectionIndex) - return *ret0, *ret1, err -} - -// GetCheckpoint is a free data retrieval call binding the contract method 0x710aeac8. -// -// Solidity: function GetCheckpoint(uint256 _sectionIndex) constant returns(bytes32, uint256) -func (_Contract *ContractSession) GetCheckpoint(_sectionIndex *big.Int) ([32]byte, *big.Int, error) { - return _Contract.Contract.GetCheckpoint(&_Contract.CallOpts, _sectionIndex) -} - -// GetCheckpoint is a free data retrieval call binding the contract method 0x710aeac8. -// -// Solidity: function GetCheckpoint(uint256 _sectionIndex) constant returns(bytes32, uint256) -func (_Contract *ContractCallerSession) GetCheckpoint(_sectionIndex *big.Int) ([32]byte, *big.Int, error) { - return _Contract.Contract.GetCheckpoint(&_Contract.CallOpts, _sectionIndex) -} - // GetLatestCheckpoint is a free data retrieval call binding the contract method 0x4d6a304c. // // Solidity: function GetLatestCheckpoint() constant returns(uint256, bytes32, uint256) diff --git a/contracts/registrar/contract/registrar.sol b/contracts/registrar/contract/registrar.sol index e00707217d..8c001e4572 100644 --- a/contracts/registrar/contract/registrar.sol +++ b/contracts/registrar/contract/registrar.sol @@ -68,22 +68,7 @@ contract Registrar { view public returns(uint, bytes32, uint) { - (bytes32 hash, uint height) = GetCheckpoint(latest); - return (latest, hash, height); - } - - /** - * @dev Get a stable checkpoint information with specified section index. - * @param _sectionIndex section index - * @return checkpoint hash - * @return the associated register block height - */ - function GetCheckpoint(uint _sectionIndex) - view - public - returns(bytes32, uint) - { - return (checkpoints[_sectionIndex], register_height[_sectionIndex]); + return (sectionIndex, hash, height); } /** @@ -115,7 +100,7 @@ contract Registrar { return false; } // Filter out stale announcement - if (_sectionIndex == latest && (latest != 0 || register_height[0] != 0)) { + if (_sectionIndex == sectionIndex && (sectionIndex != 0 || height != 0)) { return false; } // Filter out invalid announcement @@ -134,7 +119,15 @@ contract Registrar { bool isNew = (old == ""); pending_proposal.usermap[msg.sender] = _hash; - if (!isNew) { + if (isNew) { + // New checkpoint announcement + pending_proposal.count += 1; + pending_proposal.index = _sectionIndex; + pending_proposal.votemap[_hash].push(Vote({ + addr: msg.sender, + sig: _sig + })); + } else { // Checkpoint modification Vote[] storage votes = pending_proposal.votemap[old]; for (uint i = 0; i < votes.length - 1; i++) { @@ -149,21 +142,14 @@ contract Registrar { addr: msg.sender, sig: _sig })); - } else { - // New checkpoint announcement - pending_proposal.count += 1; - pending_proposal.index = _sectionIndex; - pending_proposal.votemap[_hash].push(Vote({ - addr: msg.sender, - sig: _sig - })); } if (pending_proposal.votemap[_hash].length < threshold) { return true; } - checkpoints[_sectionIndex] = _hash; - register_height[_sectionIndex] = block.number; - latest = _sectionIndex; + // Update latest checkpoint + hash = _hash; + height = block.number; + sectionIndex = _sectionIndex; bytes memory sigs; for (uint idx = 0; idx < threshold; idx++) { @@ -243,15 +229,15 @@ contract Registrar { // A list of admin users so that we can obtain all admin users. address[] adminList; - // Registered checkpoint information - mapping(uint => bytes32) checkpoints; - // Latest stored section id // Note all registered checkpoint information should continuous with previous one. - uint latest; + uint sectionIndex; // The block height associated with latest registered checkpoint. - mapping(uint => uint) register_height; + uint height; + + // The hash of latest registered checkpoint. + bytes32 hash; // The frequency for creating a checkpoint // diff --git a/les/registrar.go b/les/registrar.go index cdc7310943..e63b2c9985 100644 --- a/les/registrar.go +++ b/les/registrar.go @@ -18,7 +18,6 @@ package les import ( - "math/big" "sync/atomic" "github.com/ethereum/go-ethereum/accounts/abi/bind" @@ -87,21 +86,22 @@ func (reg *checkpointRegistrar) isRunning() bool { // stableCheckpoint returns the stable checkpoint which generated by local indexers // and announced by trusted signers. func (reg *checkpointRegistrar) stableCheckpoint() (*params.TrustedCheckpoint, uint64) { - latest, hash, _, err := reg.contract.Contract().GetLatestCheckpoint(nil) + latest, hash, height, err := reg.contract.Contract().GetLatestCheckpoint(nil) + // Short circuit if the checkpoint contract is empty. if err != nil || latest.Uint64() == 0 && hash == [32]byte{} { return nil, 0 } - index := latest.Uint64() - for { - local := reg.getLocal(index) - hash, height, err := reg.contract.Contract().GetCheckpoint(nil, big.NewInt(int64(index))) - if err == nil && local.HashEqual(common.Hash(hash)) { - return &local, height.Uint64() - } - if index == 0 { - break - } - index -= 1 + local := reg.getLocal(latest.Uint64()) + // The following scenarios may occur: + // + // * local node is out of sync so that it doesn't have the + // checkpoint which registered in the contract. + // * local checkpoint doesn't match with the registered one. + // + // In both cases, server won't send the **stable** checkpoint + // to the client(no worry, client can use hardcoded one instead). + if local.HashEqual(common.Hash(hash)) { + return &local, height.Uint64() } return nil, 0 }