Skip to content

Commit

Permalink
mixpool: Reject KEs submitted too early
Browse files Browse the repository at this point in the history
  • Loading branch information
jrick authored and davecgh committed Jul 8, 2024
1 parent b5c58ed commit 9731e3b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
8 changes: 8 additions & 0 deletions mixing/mixpool/mixpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

const minconf = 1
const feeRate = 0.0001e8
const earlyKEDuration = 5 * time.Second

type idPubKey = [33]byte

Expand Down Expand Up @@ -1394,6 +1395,13 @@ func (p *Pool) checkAcceptKE(ke *wire.MsgMixKeyExchange) error {
return ruleError(ErrPeerPositionOutOfBounds)
}

now := time.Now()
keEpoch := time.Unix(int64(ke.Epoch), 0)
if now.Add(earlyKEDuration).Before(keEpoch) {
err := fmt.Errorf("KE received too early for stated epoch")
return ruleError(err)
}

return nil
}

Expand Down
3 changes: 2 additions & 1 deletion mixing/mixpool/mixpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"math/big"
"os"
"testing"
"time"

"decred.org/cspp/v2/solverrpc"
"github.com/davecgh/go-spew/spew"
Expand Down Expand Up @@ -255,7 +256,7 @@ func TestAccept(t *testing.T) {

var (
seenPRs = []chainhash.Hash{pr.Hash()}
epoch uint64 = 0
epoch uint64 = uint64(time.Now().Unix())
sid [32]byte = mixing.SortPRsForSession([]*wire.MsgMixPairReq{pr}, epoch)
run uint32 = 0
pos uint32 = 0
Expand Down
3 changes: 2 additions & 1 deletion mixing/mixpool/orphans_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"errors"
"reflect"
"testing"
"time"

"github.com/decred/dcrd/chaincfg/chainhash"
"github.com/decred/dcrd/chaincfg/v3"
Expand Down Expand Up @@ -65,7 +66,7 @@ func TestOrphans(t *testing.T) {
pr.WriteHash(h)

prs := []*wire.MsgMixPairReq{pr}
epoch := uint64(1704067200)
epoch := uint64(time.Now().Unix())
sid := mixing.SortPRsForSession(prs, epoch)
ke := &wire.MsgMixKeyExchange{
Identity: id,
Expand Down

0 comments on commit 9731e3b

Please sign in to comment.