Skip to content

Commit 061889d

Browse files
S. Matthew Englishfjl
S. Matthew English
authored andcommitted
rlp, trie, contracts, compression, consensus: improve comments (ethereum#14580)
1 parent e3dfd55 commit 061889d

23 files changed

+44
-179
lines changed

compression/rle/read_write_test.go

Lines changed: 1 addition & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -33,102 +33,18 @@ func (s *CompressionRleSuite) TestDecompressSimple(c *checker.C) {
3333
res, err := Decompress([]byte{token, 0xfd})
3434
c.Assert(err, checker.IsNil)
3535
c.Assert(res, checker.DeepEquals, exp)
36-
// if bytes.Compare(res, exp) != 0 {
37-
// t.Error("empty sha3", res)
38-
// }
3936

4037
exp = []byte{0x56, 0xe8, 0x1f, 0x17, 0x1b, 0xcc, 0x55, 0xa6, 0xff, 0x83, 0x45, 0xe6, 0x92, 0xc0, 0xf8, 0x6e, 0x5b, 0x48, 0xe0, 0x1b, 0x99, 0x6c, 0xad, 0xc0, 0x1, 0x62, 0x2f, 0xb5, 0xe3, 0x63, 0xb4, 0x21}
4138
res, err = Decompress([]byte{token, 0xfe})
4239
c.Assert(err, checker.IsNil)
4340
c.Assert(res, checker.DeepEquals, exp)
44-
// if bytes.Compare(res, exp) != 0 {
45-
// t.Error("0x80 sha3", res)
46-
// }
4741

4842
res, err = Decompress([]byte{token, 0xff})
4943
c.Assert(err, checker.IsNil)
5044
c.Assert(res, checker.DeepEquals, []byte{token})
51-
// if bytes.Compare(res, []byte{token}) != 0 {
52-
// t.Error("token", res)
53-
// }
5445

5546
res, err = Decompress([]byte{token, 12})
5647
c.Assert(err, checker.IsNil)
5748
c.Assert(res, checker.DeepEquals, make([]byte, 10))
58-
// if bytes.Compare(res, make([]byte, 10)) != 0 {
59-
// t.Error("10 * zero", res)
60-
// }
61-
}
62-
63-
// func TestDecompressMulti(t *testing.T) {
64-
// res, err := Decompress([]byte{token, 0xfd, token, 0xfe, token, 12})
65-
// if err != nil {
66-
// t.Error(err)
67-
// }
68-
69-
// var exp []byte
70-
// exp = append(exp, crypto.Keccak256([]byte(""))...)
71-
// exp = append(exp, crypto.Keccak256([]byte{0x80})...)
72-
// exp = append(exp, make([]byte, 10)...)
73-
74-
// if bytes.Compare(res, res) != 0 {
75-
// t.Error("Expected", exp, "result", res)
76-
// }
77-
// }
78-
79-
// func TestCompressSimple(t *testing.T) {
80-
// res := Compress([]byte{0, 0, 0, 0, 0})
81-
// if bytes.Compare(res, []byte{token, 7}) != 0 {
82-
// t.Error("5 * zero", res)
83-
// }
84-
85-
// res = Compress(crypto.Keccak256([]byte("")))
86-
// if bytes.Compare(res, []byte{token, emptyShaToken}) != 0 {
87-
// t.Error("empty sha", res)
88-
// }
89-
90-
// res = Compress(crypto.Keccak256([]byte{0x80}))
91-
// if bytes.Compare(res, []byte{token, emptyListShaToken}) != 0 {
92-
// t.Error("empty list sha", res)
93-
// }
9449

95-
// res = Compress([]byte{token})
96-
// if bytes.Compare(res, []byte{token, tokenToken}) != 0 {
97-
// t.Error("token", res)
98-
// }
99-
// }
100-
101-
// func TestCompressMulti(t *testing.T) {
102-
// in := []byte{0, 0, 0, 0, 0}
103-
// in = append(in, crypto.Keccak256([]byte(""))...)
104-
// in = append(in, crypto.Keccak256([]byte{0x80})...)
105-
// in = append(in, token)
106-
// res := Compress(in)
107-
108-
// exp := []byte{token, 7, token, emptyShaToken, token, emptyListShaToken, token, tokenToken}
109-
// if bytes.Compare(res, exp) != 0 {
110-
// t.Error("expected", exp, "got", res)
111-
// }
112-
// }
113-
114-
// func TestCompressDecompress(t *testing.T) {
115-
// var in []byte
116-
117-
// for i := 0; i < 20; i++ {
118-
// in = append(in, []byte{0, 0, 0, 0, 0}...)
119-
// in = append(in, crypto.Keccak256([]byte(""))...)
120-
// in = append(in, crypto.Keccak256([]byte{0x80})...)
121-
// in = append(in, []byte{123, 2, 19, 89, 245, 254, 255, token, 98, 233}...)
122-
// in = append(in, token)
123-
// }
124-
125-
// c := Compress(in)
126-
// d, err := Decompress(c)
127-
// if err != nil {
128-
// t.Error(err)
129-
// }
130-
131-
// if bytes.Compare(d, in) != 0 {
132-
// t.Error("multi failed\n", d, "\n", in)
133-
// }
134-
// }
50+
}

consensus/clique/clique.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ var (
7676
errUnknownBlock = errors.New("unknown block")
7777

7878
// errInvalidCheckpointBeneficiary is returned if a checkpoint/epoch transition
79-
// block has a beneficiary set to non zeroes.
79+
// block has a beneficiary set to non-zeroes.
8080
errInvalidCheckpointBeneficiary = errors.New("beneficiary in checkpoint block non-zero")
8181

8282
// errInvalidVote is returned if a nonce value is something else that the two
8383
// allowed constants of 0x00..0 or 0xff..f.
8484
errInvalidVote = errors.New("vote nonce not 0x00..0 or 0xff..f")
8585

8686
// errInvalidCheckpointVote is returned if a checkpoint/epoch transition block
87-
// has a vote nonce set to non zeroes.
87+
// has a vote nonce set to non-zeroes.
8888
errInvalidCheckpointVote = errors.New("vote nonce in checkpoint block non-zero")
8989

9090
// errMissingVanity is returned if a block's extra-data section is shorter than
@@ -104,7 +104,7 @@ var (
104104
// ones).
105105
drrInvalidCheckpointSigners = errors.New("invalid signer list on checkpoint block")
106106

107-
// errInvalidMixDigest is returned if a block's mix digest is non zero.
107+
// errInvalidMixDigest is returned if a block's mix digest is non-zero.
108108
errInvalidMixDigest = errors.New("non-zero mix digest")
109109

110110
// errInvalidUncleHash is returned if a block contains an non-empty uncle list.
@@ -122,7 +122,7 @@ var (
122122
// be modified via out-of-range or non-contiguous headers.
123123
errInvalidVotingChain = errors.New("invalid voting chain")
124124

125-
// errUnauthorized is returned if a header is signed by a non authorized entity.
125+
// errUnauthorized is returned if a header is signed by a non-authorized entity.
126126
errUnauthorized = errors.New("unauthorized")
127127
)
128128

@@ -499,7 +499,7 @@ func (c *Clique) verifySeal(chain consensus.ChainReader, header *types.Header, p
499499
// Prepare implements consensus.Engine, preparing all the consensus fields of the
500500
// header for running the transactions on top.
501501
func (c *Clique) Prepare(chain consensus.ChainReader, header *types.Header) error {
502-
// If the block isn't a checkpoint, cast a random vote (good enough fror now)
502+
// If the block isn't a checkpoint, cast a random vote (good enough for now)
503503
header.Coinbase = common.Address{}
504504
header.Nonce = types.BlockNonce{}
505505

@@ -601,7 +601,7 @@ func (c *Clique) Seal(chain consensus.ChainReader, block *types.Block, stop <-ch
601601
if _, authorized := snap.Signers[signer]; !authorized {
602602
return nil, errUnauthorized
603603
}
604-
// If we're amongs the recent signers, wait for the next block
604+
// If we're amongst the recent signers, wait for the next block
605605
for seen, recent := range snap.Recents {
606606
if recent == signer {
607607
// Signer is among recents, only wait if the current block doens't shift it out

consensus/clique/snapshot.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type Vote struct {
3939
// Tally is a simple vote tally to keep the current score of votes. Votes that
4040
// go against the proposal aren't counted since it's equivalent to not voting.
4141
type Tally struct {
42-
Authorize bool `json:"authorize"` // Whether the vote it about authorizing or kicking someone
42+
Authorize bool `json:"authorize"` // Whether the vote is about authorizing or kicking someone
4343
Votes int `json:"votes"` // Number of votes until now wanting to pass the proposal
4444
}
4545

@@ -56,7 +56,7 @@ type Snapshot struct {
5656
Tally map[common.Address]Tally `json:"tally"` // Current vote tally to avoid recalculating
5757
}
5858

59-
// newSnapshot create a new snapshot with the specified startup parameters. This
59+
// newSnapshot creates a new snapshot with the specified startup parameters. This
6060
// method does not initialize the set of recent signers, so only ever use if for
6161
// the genesis block.
6262
func newSnapshot(config *params.CliqueConfig, sigcache *lru.ARCCache, number uint64, hash common.Hash, signers []common.Address) *Snapshot {

consensus/clique/snapshot_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ func TestVoting(t *testing.T) {
243243
},
244244
results: []string{"A", "B"},
245245
}, {
246-
// Cascading changes are not allowed, only the the account being voted on may change
246+
// Cascading changes are not allowed, only the account being voted on may change
247247
signers: []string{"A", "B", "C", "D"},
248248
votes: []testerVote{
249249
{signer: "A", voted: "C", auth: false},
@@ -293,7 +293,7 @@ func TestVoting(t *testing.T) {
293293
results: []string{"A", "B", "C"},
294294
}, {
295295
// Ensure that pending votes don't survive authorization status changes. This
296-
// corner case can only appear if a signer is quickly added, remove and then
296+
// corner case can only appear if a signer is quickly added, removed and then
297297
// readded (or the inverse), while one of the original voters dropped. If a
298298
// past vote is left cached in the system somewhere, this will interfere with
299299
// the final signer outcome.

consensus/consensus.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ type Engine interface {
7979

8080
// Finalize runs any post-transaction state modifications (e.g. block rewards)
8181
// and assembles the final block.
82-
//
83-
// Note, the block header and state database might be updated to reflect any
82+
// Note: The block header and state database might be updated to reflect any
8483
// consensus rules that happen at finalization (e.g. block rewards).
8584
Finalize(chain ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction,
8685
uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error)

consensus/ethash/algorithm.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ type hasher func(dest []byte, data []byte)
5353

5454
// makeHasher creates a repetitive hasher, allowing the same hash data structures
5555
// to be reused between hash runs instead of requiring new ones to be created.
56-
//
5756
// The returned function is not thread safe!
5857
func makeHasher(h hash.Hash) hasher {
5958
return func(dest []byte, data []byte) {
@@ -82,7 +81,6 @@ func seedHash(block uint64) []byte {
8281
// memory, then performing two passes of Sergio Demian Lerner's RandMemoHash
8382
// algorithm from Strict Memory Hard Hashing Functions (2014). The output is a
8483
// set of 524288 64-byte values.
85-
//
8684
// This method places the result into dest in machine byte order.
8785
func generateCache(dest []uint32, epoch uint64, seed []byte) {
8886
// Print some debug logs to allow analysis on low end devices
@@ -220,7 +218,6 @@ func generateDatasetItem(cache []uint32, index uint32, keccak512 hasher) []byte
220218
}
221219

222220
// generateDataset generates the entire ethash dataset for mining.
223-
//
224221
// This method places the result into dest in machine byte order.
225222
func generateDataset(dest []uint32, epoch uint64, cache []uint32) {
226223
// Print some debug logs to allow analysis on low end devices

consensus/ethash/algorithm_go1.8_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ package ethash
2020

2121
import "testing"
2222

23-
// Tests whether the dataset size calculator work correctly by cross checking the
23+
// Tests whether the dataset size calculator works correctly by cross checking the
2424
// hard coded lookup table with the value generated by it.
2525
func TestSizeCalculations(t *testing.T) {
2626
var tests []uint64

consensus/ethash/consensus.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ func (ethash *Ethash) VerifyUncles(chain consensus.ChainReader, block *types.Blo
218218

219219
// verifyHeader checks whether a header conforms to the consensus rules of the
220220
// stock Ethereum ethash engine.
221-
//
222221
// See YP section 4.3.4. "Block Header Validity"
223222
func (ethash *Ethash) verifyHeader(chain consensus.ChainReader, header, parent *types.Header, uncle bool, seal bool) error {
224223
// Ensure that the header's extra-data section is of a reasonable size
@@ -286,7 +285,6 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainReader, header, parent *
286285
// CalcDifficulty is the difficulty adjustment algorithm. It returns
287286
// the difficulty that a new block should have when created at time
288287
// given the parent block's time and difficulty.
289-
//
290288
// TODO (karalabe): Move the chain maker into this package and make this private!
291289
func CalcDifficulty(config *params.ChainConfig, time uint64, parent *types.Header) *big.Int {
292290
next := new(big.Int).Add(parent.Number, common.Big1)
@@ -462,7 +460,6 @@ var (
462460
// AccumulateRewards credits the coinbase of the given block with the mining
463461
// reward. The total reward consists of the static block reward and rewards for
464462
// included uncles. The coinbase of each uncle block is also rewarded.
465-
//
466463
// TODO (karalabe): Move the chain maker into this package and make this private!
467464
func AccumulateRewards(state *state.StateDB, header *types.Header, uncles []*types.Header) {
468465
reward := new(big.Int).Set(blockReward)

consensus/ethash/ethash.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ type Ethash struct {
355355
// New creates a full sized ethash PoW scheme.
356356
func New(cachedir string, cachesinmem, cachesondisk int, dagdir string, dagsinmem, dagsondisk int) *Ethash {
357357
if cachesinmem <= 0 {
358-
log.Warn("One ethash cache must alwast be in memory", "requested", cachesinmem)
358+
log.Warn("One ethash cache must always be in memory", "requested", cachesinmem)
359359
cachesinmem = 1
360360
}
361361
if cachedir != "" && cachesondisk > 0 {
@@ -412,7 +412,7 @@ func NewFakeDelayer(delay time.Duration) *Ethash {
412412
return &Ethash{fakeMode: true, fakeDelay: delay}
413413
}
414414

415-
// NewFullFaker creates a ethash consensus engine with a full fake scheme that
415+
// NewFullFaker creates an ethash consensus engine with a full fake scheme that
416416
// accepts all blocks as valid, without checking any consensus rules whatsoever.
417417
func NewFullFaker() *Ethash {
418418
return &Ethash{fakeMode: true, fakeFull: true}

consensus/misc/dao.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func VerifyDAOHeaderExtraData(config *params.ChainConfig, header *types.Header)
5454
if header.Number.Cmp(config.DAOForkBlock) < 0 || header.Number.Cmp(limit) >= 0 {
5555
return nil
5656
}
57-
// Depending whether we support or oppose the fork, validate the extra-data contents
57+
// Depending on whether we support or oppose the fork, validate the extra-data contents
5858
if config.DAOForkSupport {
5959
if !bytes.Equal(header.Extra, params.DAOForkBlockExtra) {
6060
return ErrBadProDAOExtra

contracts/chequebook/cheque.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import (
4949
// TODO(zelig): watch peer solvency and notify of bouncing cheques
5050
// TODO(zelig): enable paying with cheque by signing off
5151

52-
// Some functionality require interacting with the blockchain:
52+
// Some functionality requires interacting with the blockchain:
5353
// * setting current balance on peer's chequebook
5454
// * sending the transaction to cash the cheque
5555
// * depositing ether to the chequebook
@@ -100,13 +100,13 @@ type Chequebook struct {
100100
// persisted fields
101101
balance *big.Int // not synced with blockchain
102102
contractAddr common.Address // contract address
103-
sent map[common.Address]*big.Int //tallies for beneficiarys
103+
sent map[common.Address]*big.Int //tallies for beneficiaries
104104

105105
txhash string // tx hash of last deposit tx
106106
threshold *big.Int // threshold that triggers autodeposit if not nil
107107
buffer *big.Int // buffer to keep on top of balance for fork protection
108108

109-
log log.Logger // contextual logger with the contrac address embedded
109+
log log.Logger // contextual logger with the contract address embedded
110110
}
111111

112112
func (self *Chequebook) String() string {
@@ -442,7 +442,7 @@ type Inbox struct {
442442
maxUncashed *big.Int // threshold that triggers autocashing
443443
cashed *big.Int // cumulative amount cashed
444444
cheque *Cheque // last cheque, nil if none yet received
445-
log log.Logger // contextual logger with the contrac address embedded
445+
log log.Logger // contextual logger with the contract address embedded
446446
}
447447

448448
// NewInbox creates an Inbox. An Inboxes is not persisted, the cumulative sum is updated
@@ -509,9 +509,8 @@ func (self *Inbox) AutoCash(cashInterval time.Duration, maxUncashed *big.Int) {
509509
self.autoCash(cashInterval)
510510
}
511511

512-
// autoCash starts a loop that periodically clears the last check
512+
// autoCash starts a loop that periodically clears the last cheque
513513
// if the peer is trusted. Clearing period could be 24h or a week.
514-
//
515514
// The caller must hold self.lock.
516515
func (self *Inbox) autoCash(cashInterval time.Duration) {
517516
if self.quit != nil {
@@ -557,10 +556,10 @@ func (self *Inbox) Receive(promise swap.Promise) (*big.Int, error) {
557556

558557
var sum *big.Int
559558
if self.cheque == nil {
560-
// the sum is checked against the blockchain once a check is received
559+
// the sum is checked against the blockchain once a cheque is received
561560
tally, err := self.session.Sent(self.beneficiary)
562561
if err != nil {
563-
return nil, fmt.Errorf("inbox: error calling backend to set amount: %v", err)
562+
return nil, fmt.Errorf("inbox: error calling backend to set amount: %v", err)
564563
}
565564
sum = tally
566565
} else {

0 commit comments

Comments
 (0)