all: format golang files (#1548)

Co-authored-by: wit <wit765765346@gmail>
This commit is contained in:
wit liu 2025-09-21 19:41:54 +08:00 committed by GitHub
parent 03c18e9d47
commit d9ae317a38
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 122 additions and 119 deletions

View file

@ -113,7 +113,7 @@ func (Failure_FailureType) EnumDescriptor() ([]byte, []int) {
return file_messages_common_proto_rawDescGZIP(), []int{1, 0}
}
//*
// *
// Type of button request
type ButtonRequest_ButtonRequestType int32
@ -210,7 +210,7 @@ func (ButtonRequest_ButtonRequestType) EnumDescriptor() ([]byte, []int) {
return file_messages_common_proto_rawDescGZIP(), []int{2, 0}
}
//*
// *
// Type of PIN request
type PinMatrixRequest_PinMatrixRequestType int32
@ -271,7 +271,7 @@ func (PinMatrixRequest_PinMatrixRequestType) EnumDescriptor() ([]byte, []int) {
return file_messages_common_proto_rawDescGZIP(), []int{4, 0}
}
//*
// *
// Response: Success of the previous request
// @end
type Success struct {
@ -321,7 +321,7 @@ func (x *Success) GetMessage() string {
return ""
}
//*
// *
// Response: Failure of the previous request
// @end
type Failure struct {
@ -379,7 +379,7 @@ func (x *Failure) GetMessage() string {
return ""
}
//*
// *
// Response: Device is waiting for HW button press.
// @auxstart
// @next ButtonAck
@ -438,7 +438,7 @@ func (x *ButtonRequest) GetData() string {
return ""
}
//*
// *
// Request: Computer agrees to wait for HW button press
// @auxend
type ButtonAck struct {
@ -530,7 +530,7 @@ func (x *PinMatrixRequest) GetType() PinMatrixRequest_PinMatrixRequestType {
return PinMatrixRequest_PinMatrixRequestType_Current
}
//*
// *
// Request: Computer responds with encoded PIN
// @auxend
type PinMatrixAck struct {
@ -580,7 +580,7 @@ func (x *PinMatrixAck) GetPin() string {
return ""
}
//*
// *
// Response: Device awaits encryption passphrase
// @auxstart
// @next PassphraseAck
@ -631,7 +631,7 @@ func (x *PassphraseRequest) GetOnDevice() bool {
return false
}
//*
// *
// Request: Send passphrase back
// @next PassphraseStateRequest
type PassphraseAck struct {
@ -689,7 +689,7 @@ func (x *PassphraseAck) GetState() []byte {
return nil
}
//*
// *
// Response: Device awaits passphrase state
// @next PassphraseStateAck
type PassphraseStateRequest struct {
@ -739,7 +739,7 @@ func (x *PassphraseStateRequest) GetState() []byte {
return nil
}
//*
// *
// Request: Send passphrase state back
// @auxend
type PassphraseStateAck struct {

View file

@ -24,7 +24,7 @@ const (
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
//*
// *
// Request: Ask device for public key corresponding to address_n path
// @start
// @next EthereumPublicKey
@ -84,7 +84,7 @@ func (x *EthereumGetPublicKey) GetShowDisplay() bool {
return false
}
//*
// *
// Response: Contains public key derived from device private seed
// @end
type EthereumPublicKey struct {
@ -142,7 +142,7 @@ func (x *EthereumPublicKey) GetXpub() string {
return ""
}
//*
// *
// Request: Ask device for Ethereum address corresponding to address_n path
// @start
// @next EthereumAddress
@ -202,7 +202,7 @@ func (x *EthereumGetAddress) GetShowDisplay() bool {
return false
}
//*
// *
// Response: Contains an Ethereum address derived from device private seed
// @end
type EthereumAddress struct {
@ -260,7 +260,7 @@ func (x *EthereumAddress) GetAddressHex() string {
return ""
}
//*
// *
// Request: Ask device to sign transaction
// All fields are optional from the protocol's point of view. Each field defaults to value `0` if missing.
// Note: the first at most 1024 bytes of data MUST be transmitted as part of this message.
@ -394,7 +394,7 @@ func (x *EthereumSignTx) GetTxType() uint32 {
return 0
}
//*
// *
// Response: Device asks for more data from transaction payload, or returns the signature.
// If data_length is set, device awaits that many more bytes of payload.
// Otherwise, the signature_* fields contain the computed transaction signature. All three fields will be present.
@ -471,7 +471,7 @@ func (x *EthereumTxRequest) GetSignatureS() []byte {
return nil
}
//*
// *
// Request: Transaction payload data.
// @next EthereumTxRequest
type EthereumTxAck struct {
@ -521,7 +521,7 @@ func (x *EthereumTxAck) GetDataChunk() []byte {
return nil
}
//*
// *
// Request: Ask device to sign message
// @start
// @next EthereumMessageSignature
@ -581,7 +581,7 @@ func (x *EthereumSignMessage) GetMessage() []byte {
return nil
}
//*
// *
// Response: Signed message
// @end
type EthereumMessageSignature struct {
@ -647,7 +647,7 @@ func (x *EthereumMessageSignature) GetAddressHex() string {
return ""
}
//*
// *
// Request: Ask device to verify message
// @start
// @next Success

View file

@ -24,7 +24,7 @@ const (
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
//*
// *
// Structure representing passphrase source
type ApplySettings_PassphraseSourceType int32
@ -85,7 +85,7 @@ func (ApplySettings_PassphraseSourceType) EnumDescriptor() ([]byte, []int) {
return file_messages_management_proto_rawDescGZIP(), []int{4, 0}
}
//*
// *
// Type of recovery procedure. These should be used as bitmask, e.g.,
// `RecoveryDeviceType_ScrambledWords | RecoveryDeviceType_Matrix`
// listing every method supported by the host computer.
@ -149,7 +149,7 @@ func (RecoveryDevice_RecoveryDeviceType) EnumDescriptor() ([]byte, []int) {
return file_messages_management_proto_rawDescGZIP(), []int{17, 0}
}
//*
// *
// Type of Recovery Word request
type WordRequest_WordRequestType int32
@ -210,7 +210,7 @@ func (WordRequest_WordRequestType) EnumDescriptor() ([]byte, []int) {
return file_messages_management_proto_rawDescGZIP(), []int{18, 0}
}
//*
// *
// Request: Reset device to default state and ask for device details
// @start
// @next Features
@ -269,7 +269,7 @@ func (x *Initialize) GetSkipPassphrase() bool {
return false
}
//*
// *
// Request: Ask for device details (no device reset)
// @start
// @next Features
@ -569,7 +569,7 @@ func (x *Features) GetNoBackup() bool {
return false
}
//*
// *
// Request: clear session (removes cached PIN, passphrase, etc).
// @start
// @next Success
@ -711,7 +711,7 @@ func (x *ApplySettings) GetDisplayRotation() uint32 {
return 0
}
//*
// *
// Request: set flags of the device
// @start
// @next Success
@ -763,7 +763,7 @@ func (x *ApplyFlags) GetFlags() uint32 {
return 0
}
//*
// *
// Request: Starts workflow for setting/changing/removing the PIN
// @start
// @next Success
@ -815,7 +815,7 @@ func (x *ChangePin) GetRemove() bool {
return false
}
//*
// *
// Request: Test if the device is alive, device sends back the message in Success response
// @start
// @next Success
@ -890,7 +890,7 @@ func (x *Ping) GetPassphraseProtection() bool {
return false
}
//*
// *
// Request: Abort last operation that required user interaction
// @start
// @next Failure
@ -984,7 +984,7 @@ func (x *GetEntropy) GetSize() uint32 {
return 0
}
//*
// *
// Response: Reply with random data generated by internal RNG
// @end
type Entropy struct {
@ -1034,7 +1034,7 @@ func (x *Entropy) GetEntropy() []byte {
return nil
}
//*
// *
// Request: Request device to wipe all sensitive data and settings
// @start
// @next Success
@ -1190,7 +1190,7 @@ func (x *LoadDevice) GetU2FCounter() uint32 {
return 0
}
//*
// *
// Request: Ask device to do initialization involving user interaction
// @start
// @next EntropyRequest
@ -1312,7 +1312,7 @@ func (x *ResetDevice) GetNoBackup() bool {
return false
}
//*
// *
// Request: Perform backup of the device seed if not backed up using ResetDevice
// @start
// @next Success
@ -1445,7 +1445,7 @@ func (x *EntropyAck) GetEntropy() []byte {
return nil
}
//*
// *
// Request: Start recovery workflow asking user for specific words of mnemonic
// Used to recovery device safely even on untrusted computer.
// @start
@ -1567,7 +1567,7 @@ func (x *RecoveryDevice) GetDryRun() bool {
return false
}
//*
// *
// Response: Device is waiting for user to enter word of the mnemonic
// Its position is shown only on device's internal display.
// @next WordAck
@ -1618,7 +1618,7 @@ func (x *WordRequest) GetType() WordRequest_WordRequestType {
return WordRequest_WordRequestType_Plain
}
//*
// *
// Request: Computer replies with word from the mnemonic
// @next WordRequest
// @next Success
@ -1670,7 +1670,7 @@ func (x *WordAck) GetWord() string {
return ""
}
//*
// *
// Request: Set U2F counter
// @start
// @next Success

View file

@ -25,7 +25,7 @@ const (
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
//*
// *
// Mapping between TREZOR wire identifier (uint) and a protobuf message
type MessageType int32

View file

@ -298,9 +298,9 @@ func TestShouldNotSendVoteMsgIfBlockInfoRoundNotEqualCurrentRound(t *testing.T)
}
/*
Block and round relationship diagram for this test
... - 13(3) - 14(4) - 15(5) - 16(6)
\ 14'(7)
Block and round relationship diagram for this test
... - 13(3) - 14(4) - 15(5) - 16(6)
\ 14'(7)
*/
func TestShouldNotSendVoteMsgIfBlockNotExtendedFromAncestor(t *testing.T) {
// Block number 905, 906 have forks and forkedBlock is the 906th

View file

@ -19,19 +19,19 @@ var _ = (*genesisSpecMarshaling)(nil)
// MarshalJSON marshals as JSON.
func (g Genesis) MarshalJSON() ([]byte, error) {
type Genesis struct {
Config *params.ChainConfig `json:"config"`
Nonce math.HexOrDecimal64 `json:"nonce"`
Timestamp math.HexOrDecimal64 `json:"timestamp"`
ExtraData hexutil.Bytes `json:"extraData"`
GasLimit math.HexOrDecimal64 `json:"gasLimit" gencodec:"required"`
Difficulty *math.HexOrDecimal256 `json:"difficulty" gencodec:"required"`
Mixhash common.Hash `json:"mixHash"`
Coinbase common.Address `json:"coinbase"`
Config *params.ChainConfig `json:"config"`
Nonce math.HexOrDecimal64 `json:"nonce"`
Timestamp math.HexOrDecimal64 `json:"timestamp"`
ExtraData hexutil.Bytes `json:"extraData"`
GasLimit math.HexOrDecimal64 `json:"gasLimit" gencodec:"required"`
Difficulty *math.HexOrDecimal256 `json:"difficulty" gencodec:"required"`
Mixhash common.Hash `json:"mixHash"`
Coinbase common.Address `json:"coinbase"`
Alloc map[common.UnprefixedAddress]types.Account `json:"alloc" gencodec:"required"`
Number math.HexOrDecimal64 `json:"number"`
GasUsed math.HexOrDecimal64 `json:"gasUsed"`
ParentHash common.Hash `json:"parentHash"`
BaseFee *math.HexOrDecimal256 `json:"baseFeePerGas"`
Number math.HexOrDecimal64 `json:"number"`
GasUsed math.HexOrDecimal64 `json:"gasUsed"`
ParentHash common.Hash `json:"parentHash"`
BaseFee *math.HexOrDecimal256 `json:"baseFeePerGas"`
}
var enc Genesis
enc.Config = g.Config
@ -58,19 +58,19 @@ func (g Genesis) MarshalJSON() ([]byte, error) {
// UnmarshalJSON unmarshals from JSON.
func (g *Genesis) UnmarshalJSON(input []byte) error {
type Genesis struct {
Config *params.ChainConfig `json:"config"`
Nonce *math.HexOrDecimal64 `json:"nonce"`
Timestamp *math.HexOrDecimal64 `json:"timestamp"`
ExtraData *hexutil.Bytes `json:"extraData"`
GasLimit *math.HexOrDecimal64 `json:"gasLimit" gencodec:"required"`
Difficulty *math.HexOrDecimal256 `json:"difficulty" gencodec:"required"`
Mixhash *common.Hash `json:"mixHash"`
Coinbase *common.Address `json:"coinbase"`
Config *params.ChainConfig `json:"config"`
Nonce *math.HexOrDecimal64 `json:"nonce"`
Timestamp *math.HexOrDecimal64 `json:"timestamp"`
ExtraData *hexutil.Bytes `json:"extraData"`
GasLimit *math.HexOrDecimal64 `json:"gasLimit" gencodec:"required"`
Difficulty *math.HexOrDecimal256 `json:"difficulty" gencodec:"required"`
Mixhash *common.Hash `json:"mixHash"`
Coinbase *common.Address `json:"coinbase"`
Alloc map[common.UnprefixedAddress]types.Account `json:"alloc" gencodec:"required"`
Number *math.HexOrDecimal64 `json:"number"`
GasUsed *math.HexOrDecimal64 `json:"gasUsed"`
ParentHash *common.Hash `json:"parentHash"`
BaseFee *math.HexOrDecimal256 `json:"baseFeePerGas"`
Number *math.HexOrDecimal64 `json:"number"`
GasUsed *math.HexOrDecimal64 `json:"gasUsed"`
ParentHash *common.Hash `json:"parentHash"`
BaseFee *math.HexOrDecimal256 `json:"baseFeePerGas"`
}
var dec Genesis
if err := json.Unmarshal(input, &dec); err != nil {

File diff suppressed because one or more lines are too long

View file

@ -489,7 +489,7 @@ func (h *priceHeap) Pop() interface{} {
// better candidates for inclusion while in other cases (at the top of the baseFee peak)
// the floating heap is better. When baseFee is decreasing they behave similarly.
type pricedList struct {
all *lookup // Pointer to the map of all transactions
all *lookup // Pointer to the map of all transactions
urgent, floating priceHeap // Heaps of prices of all the stored **remote** transactions
stales int64 // Number of stale price points to (re-heap trigger)
reheapMu sync.Mutex // Mutex asserts that only one routine is reheaping the list

View file

@ -19,4 +19,3 @@ import (
_ "github.com/XinFinOrg/XDPoSChain/crypto/secp256k1/libsecp256k1/src"
_ "github.com/XinFinOrg/XDPoSChain/crypto/secp256k1/libsecp256k1/src/modules/recovery"
)

View file

@ -477,9 +477,10 @@ func (q *queue) ReserveReceipts(p *peerConnection, count int) (*fetchRequest, bo
// to access the queue, so they already need a lock anyway.
//
// Returns:
// item - the fetchRequest
// progress - whether any progress was made
// throttle - if the caller should throttle for a while
//
// item - the fetchRequest
// progress - whether any progress was made
// throttle - if the caller should throttle for a while
func (q *queue) reserveHeaders(p *peerConnection, count int, taskPool map[common.Hash]*types.Header, taskQueue *prque.Prque[int64, *types.Header],
pendPool map[string]*fetchRequest, kind uint) (*fetchRequest, bool, bool) {
// Short circuit if the pool has been depleted, or if the peer's already

View file

@ -71,10 +71,11 @@ func (r *resultStore) SetThrottleThreshold(threshold uint64) uint64 {
// wants to reserve headers for fetching.
//
// It returns the following:
// stale - if true, this item is already passed, and should not be requested again
// throttled - if true, the store is at capacity, this particular header is not prio now
// item - the result to store data into
// err - any error that occurred
//
// stale - if true, this item is already passed, and should not be requested again
// throttled - if true, the store is at capacity, this particular header is not prio now
// item - the result to store data into
// err - any error that occurred
func (r *resultStore) AddFetch(header *types.Header, fastSync bool) (stale, throttled bool, item *fetchResult, err error) {
r.lock.Lock()
defer r.lock.Unlock()

View file

@ -14,6 +14,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
//go:build go1.4 && nacl && faketime_simulation
// +build go1.4,nacl,faketime_simulation
package discv5

View file

@ -14,7 +14,8 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
//+build !windows
//go:build !windows
// +build !windows
package netutil

View file

@ -14,7 +14,8 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
//+build windows
//go:build windows
// +build windows
package netutil

View file

@ -28,20 +28,20 @@ import (
"github.com/XinFinOrg/XDPoSChain/p2p/discover"
)
//a map of mocker names to its function
// a map of mocker names to its function
var mockerList = map[string]func(net *Network, quit chan struct{}, nodeCount int){
"startStop": startStop,
"probabilistic": probabilistic,
"boot": boot,
}
//Lookup a mocker by its name, returns the mockerFn
// Lookup a mocker by its name, returns the mockerFn
func LookupMocker(mockerType string) func(net *Network, quit chan struct{}, nodeCount int) {
return mockerList[mockerType]
}
//Get a list of mockers (keys of the map)
//Useful for frontend to build available mocker selection
// Get a list of mockers (keys of the map)
// Useful for frontend to build available mocker selection
func GetMockerList() []string {
list := make([]string, 0, len(mockerList))
for k := range mockerList {
@ -50,7 +50,7 @@ func GetMockerList() []string {
return list
}
//The boot mockerFn only connects the node in a ring and doesn't do anything else
// The boot mockerFn only connects the node in a ring and doesn't do anything else
func boot(net *Network, quit chan struct{}, nodeCount int) {
_, err := connectNodesInRing(net, nodeCount)
if err != nil {
@ -58,7 +58,7 @@ func boot(net *Network, quit chan struct{}, nodeCount int) {
}
}
//The startStop mockerFn stops and starts nodes in a defined period (ticker)
// The startStop mockerFn stops and starts nodes in a defined period (ticker)
func startStop(net *Network, quit chan struct{}, nodeCount int) {
nodes, err := connectNodesInRing(net, nodeCount)
if err != nil {
@ -95,10 +95,10 @@ func startStop(net *Network, quit chan struct{}, nodeCount int) {
}
}
//The probabilistic mocker func has a more probabilistic pattern
//(the implementation could probably be improved):
//nodes are connected in a ring, then a varying number of random nodes is selected,
//mocker then stops and starts them in random intervals, and continues the loop
// The probabilistic mocker func has a more probabilistic pattern
// (the implementation could probably be improved):
// nodes are connected in a ring, then a varying number of random nodes is selected,
// mocker then stops and starts them in random intervals, and continues the loop
func probabilistic(net *Network, quit chan struct{}, nodeCount int) {
nodes, err := connectNodesInRing(net, nodeCount)
if err != nil {
@ -161,7 +161,7 @@ func probabilistic(net *Network, quit chan struct{}, nodeCount int) {
}
//connect nodeCount number of nodes in a ring
// connect nodeCount number of nodes in a ring
func connectNodesInRing(net *Network, nodeCount int) ([]discover.NodeID, error) {
ids := make([]discover.NodeID, nodeCount)
for i := 0; i < nodeCount; i++ {

View file

@ -15,7 +15,6 @@
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
/*
Package rpc implements bi-directional JSON-RPC 2.0 on multiple transports.
It provides access to the exported methods of an object across a network or other I/O
@ -23,16 +22,16 @@ connection. After creating a server or client instance, objects can be registere
them visible as 'services'. Exported methods that follow specific conventions can be
called remotely. It also has support for the publish/subscribe pattern.
RPC Methods
# RPC Methods
Methods that satisfy the following criteria are made available for remote access:
- method must be exported
- method returns 0, 1 (response or error) or 2 (response and error) values
- method must be exported
- method returns 0, 1 (response or error) or 2 (response and error) values
An example method:
func (s *CalcService) Add(a, b int) (int, error)
func (s *CalcService) Add(a, b int) (int, error)
When the returned error isn't nil the returned integer is ignored and the error is sent
back to the client. Otherwise the returned integer is sent back to the client.
@ -41,7 +40,7 @@ Optional arguments are supported by accepting pointer values as arguments. E.g.
to do the addition in an optional finite field we can accept a mod argument as pointer
value.
func (s *CalcService) Add(a, b int, mod *int) (int, error)
func (s *CalcService) Add(a, b int, mod *int) (int, error)
This RPC method can be called with 2 integers and a null value as third argument. In that
case the mod argument will be nil. Or it can be called with 3 integers, in that case mod
@ -56,40 +55,40 @@ to the client out of order.
An example server which uses the JSON codec:
type CalculatorService struct {}
type CalculatorService struct {}
func (s *CalculatorService) Add(a, b int) int {
return a + b
}
func (s *CalculatorService) Add(a, b int) int {
return a + b
}
func (s *CalculatorService) Div(a, b int) (int, error) {
if b == 0 {
return 0, errors.New("divide by zero")
}
return a/b, nil
}
func (s *CalculatorService) Div(a, b int) (int, error) {
if b == 0 {
return 0, errors.New("divide by zero")
}
return a/b, nil
}
calculator := new(CalculatorService)
server := NewServer()
server.RegisterName("calculator", calculator)
l, _ := net.ListenUnix("unix", &net.UnixAddr{Net: "unix", Name: "/tmp/calculator.sock"})
server.ServeListener(l)
calculator := new(CalculatorService)
server := NewServer()
server.RegisterName("calculator", calculator)
l, _ := net.ListenUnix("unix", &net.UnixAddr{Net: "unix", Name: "/tmp/calculator.sock"})
server.ServeListener(l)
Subscriptions
# Subscriptions
The package also supports the publish subscribe pattern through the use of subscriptions.
A method that is considered eligible for notifications must satisfy the following
criteria:
- method must be exported
- first method argument type must be context.Context
- method must have return types (rpc.Subscription, error)
- method must be exported
- first method argument type must be context.Context
- method must have return types (rpc.Subscription, error)
An example method:
func (s *BlockChainService) NewBlocks(ctx context.Context) (rpc.Subscription, error) {
...
}
func (s *BlockChainService) NewBlocks(ctx context.Context) (rpc.Subscription, error) {
...
}
When the service containing the subscription method is registered to the server, for
example under the "blockchain" namespace, a subscription is created by calling the
@ -101,7 +100,7 @@ the client and server. The server will close the connection for any write error.
For more information about subscriptions, see https://geth.ethereum.org/docs/interacting-with-geth/rpc/pubsub
Reverse Calls
# Reverse Calls
In any method handler, an instance of rpc.Client can be accessed through the
ClientFromContext method. Using this client instance, server-to-client method calls can be