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 committed Jul 8, 2024
1 parent 02a286d commit f16f4f2
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.Before(keEpoch) && keEpoch.Sub(now) > earlyKEDuration {
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 f16f4f2

Please sign in to comment.