Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into pedro/enhance_tx_bu…
Browse files Browse the repository at this point in the history
…ilder
  • Loading branch information
otherview committed Sep 23, 2024
2 parents f07dc43 + fd5e569 commit e267e13
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 16 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/gosec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Gosec
on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
tests:
runs-on: ubuntu-latest
env:
GO111MODULE: on
steps:
- name: Checkout Source
uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.22'
cache: false
- name: Run Gosec
uses: securego/gosec@master
with:
args: '-exclude=G104,G115,G304,G406,G507 -exclude-dir=builtin/gen ./...'
2 changes: 0 additions & 2 deletions .github/workflows/lint-go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,3 @@ jobs:
args: --timeout=30m --config=.golangci.yml
only-new-issues: true
skip-cache: true
skip-pkg-cache: true
skip-build-cache: true
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ run:
tests: true
# default is true. Enables skipping of directories:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs-use-default: true
exclude-dirs-use-default: true

linters:
disable-all: true
Expand Down
4 changes: 2 additions & 2 deletions cache/rnd_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (rc *RandCache) Pick() *Entry {
if len(rc.s) == 0 {
return nil
}
ent := rc.s[rand.Intn(len(rc.s))] // nolint:gosec
ent := rc.s[rand.Intn(len(rc.s))] // #nosec
cpy := ent.Entry
return &cpy
}
Expand Down Expand Up @@ -141,6 +141,6 @@ func (rc *RandCache) randDrop() {
if len(rc.s) == 0 {
return
}
ent := rc.s[rand.Intn(len(rc.s))] // nolint:gosec
ent := rc.s[rand.Intn(len(rc.s))] // #nosec
rc.remove(ent.Key)
}
2 changes: 1 addition & 1 deletion cmd/thor/solo/solo.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func (s *Solo) newTx(clauses []*tx.Clause, from genesis.DevAccount) (*tx.Transac

return builder.BlockRef(tx.NewBlockRef(0)).
Expiration(math.MaxUint32).
Nonce(rand.Uint64()). // nolint:gosec
Nonce(rand.Uint64()). // #nosec
DependsOn(nil).
Gas(1_000_000).
BuildAndSign(from.PrivateKey)
Expand Down
2 changes: 1 addition & 1 deletion comm/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (p *Peer) UpdateHead(id thor.Bytes32, totalScore uint64) {
// MarkTransaction marks a transaction to known.
func (p *Peer) MarkTransaction(hash thor.Bytes32) {
// that's 10~100 block intervals
expiration := mclock.AbsTime(time.Second * time.Duration(thor.BlockInterval*uint64(rand.Intn(91)+10))) // nolint:gosec
expiration := mclock.AbsTime(time.Second * time.Duration(thor.BlockInterval*uint64(rand.Intn(91)+10))) // #nosec

deadline := mclock.Now() + expiration
p.knownTxs.Add(hash, deadline)
Expand Down
2 changes: 1 addition & 1 deletion p2psrv/rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (r *RPC) prepareCall(msgCode uint64, onResult func(*p2p.Msg) error) uint32
r.lock.Lock()
defer r.lock.Unlock()
for {
id := rand.Uint32() // nolint:gosec
id := rand.Uint32() // #nosec
if id == 0 {
// 0 id is taken by Notify
continue
Expand Down
4 changes: 2 additions & 2 deletions test/datagen/numbers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
)

func RandInt() int {
return mathrand.Int() // nolint:gosec
return mathrand.Int() // #nosec
}

func RandIntN(n int) int {
return mathrand.Intn(n) // nolint:gosec
return mathrand.Intn(n) // #nosec
}
8 changes: 3 additions & 5 deletions txpool/tx_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (o *txObject) Executable(chain *chain.Chain, state *state.State, headBlock
switch {
case o.Gas() > headBlock.GasLimit():
return false, errors.New("gas too large")
case o.IsExpired(headBlock.Number()):
case o.IsExpired(headBlock.Number() + 1): // Check tx expiration on top of next block
return false, errors.New("expired")
case o.BlockRef().Number() > headBlock.Number()+uint32(5*60/thor.BlockInterval):
// reject deferred tx which will be applied after 5mins
Expand All @@ -81,13 +81,11 @@ func (o *txObject) Executable(chain *chain.Chain, state *state.State, headBlock
}
}

if o.BlockRef().Number() > headBlock.Number() {
// Tx is considered executable when the BlockRef has passed in reference to the next block.
if o.BlockRef().Number() > headBlock.Number()+1 {
return false, nil
}

// checkpoint := state.NewCheckpoint()
// defer state.RevertTo(checkpoint)

if _, _, _, _, err := o.resolved.BuyGas(state, headBlock.Timestamp()+thor.BlockInterval); err != nil {
return false, err
}
Expand Down
2 changes: 1 addition & 1 deletion txpool/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (p *TxPool) fetchBlocklistLoop() {

for {
// delay 1~2 min
delay := time.Second * time.Duration(rand.Int()%60+60) // nolint:gosec
delay := time.Second * time.Duration(rand.Int()%60+60) // #nosec
select {
case <-p.ctx.Done():
return
Expand Down

0 comments on commit e267e13

Please sign in to comment.