さよなら

This commit is contained in:
Cassandra Heart 2024-11-26 18:50:25 -06:00
parent e836b00852
commit 75716be4fa
No known key found for this signature in database
GPG Key ID: 6352152859385958
3 changed files with 32 additions and 3 deletions

View File

@ -121,7 +121,7 @@ type DataClockConsensusEngine struct {
dependencyMapMx sync.Mutex
stagedTransactions *protobufs.TokenRequests
stagedTransactionsSet map[string]struct{}
stagedTransactionsMx sync.Mutex
stagedTransactionsMx sync.RWMutex
peerMapMx sync.RWMutex
peerAnnounceMapMx sync.Mutex
lastKeyBundleAnnouncementFrame uint64
@ -270,7 +270,8 @@ func NewDataClockConsensusEngine(
rateLimit,
time.Minute,
),
requestSyncCh: make(chan struct{}, 1),
requestSyncCh: make(chan struct{}, 1),
stagedTransactionsSet: map[string]struct{}{},
}
logger.Info("constructing consensus engine")

View File

@ -2,6 +2,7 @@ package data
import (
"bytes"
"encoding/binary"
"fmt"
"sync"
"time"
@ -381,6 +382,9 @@ func TokenRequestIdentifiers(transition *protobufs.TokenRequest) []string {
case *protobufs.TokenRequest_Mint:
if len(t.Mint.Proofs) == 1 {
return []string{fmt.Sprintf("mint-proof-%x", sha3.Sum512(t.Mint.Proofs[0]))}
} else if len(t.Mint.Proofs) >= 3 {
frameNumber := binary.BigEndian.Uint64(t.Mint.Proofs[2])
return []string{fmt.Sprintf("mint-sign-%d-%x", frameNumber, t.Mint.Signature.PublicKey.KeyValue)}
}
return []string{fmt.Sprintf("mint-sign-%x", t.Mint.Signature.PublicKey.KeyValue)}
case *protobufs.TokenRequest_Announce:

View File

@ -2,6 +2,7 @@ package data
import (
"encoding/binary"
"fmt"
"time"
"github.com/libp2p/go-libp2p/core/peer"
@ -61,11 +62,34 @@ func (e *DataClockConsensusEngine) validateTxMessage(peerID peer.ID, message *pb
if len(mint.Proofs[2]) != 8 {
return p2p.ValidationResultReject
}
if mint.Signature == nil ||
mint.Signature.PublicKey == nil ||
mint.Signature.PublicKey.KeyValue == nil {
return p2p.ValidationResultReject
}
head, err := e.dataTimeReel.Head()
if err != nil {
panic(err)
}
if frameNumber := binary.BigEndian.Uint64(mint.Proofs[2]); frameNumber+2 < head.FrameNumber {
// cheap hack for handling protobuf trickery: because protobufs can be
// serialized in infinite ways, message ids can be regenerated simply by
// modifying the data without affecting the underlying signed message.
// if this is encountered, go scorched earth on the sender a thank you
// message for destabilizing the network.
frameNumber := binary.BigEndian.Uint64(mint.Proofs[2])
id := fmt.Sprintf(
"mint-sign-%d-%x",
frameNumber,
mint.Signature.PublicKey.KeyValue,
)
e.stagedTransactionsMx.RLock()
_, ok := e.stagedTransactionsSet[id]
e.stagedTransactionsMx.RUnlock()
if ok {
return p2p.ValidationResultReject
}
if frameNumber+2 < head.FrameNumber {
return p2p.ValidationResultIgnore
}
}