mirror of
https://github.com/QuilibriumNetwork/ceremonyclient.git
synced 2026-02-21 10:27:26 +08:00
Add transaction timestamps (#354)
This commit is contained in:
parent
7819548b6f
commit
d57d76e627
@ -631,6 +631,7 @@ func (e *DataClockConsensusEngine) Stop(force bool) <-chan error {
|
||||
},
|
||||
},
|
||||
},
|
||||
Timestamp: time.Now().UnixMilli(),
|
||||
})
|
||||
|
||||
wg := sync.WaitGroup{}
|
||||
|
||||
@ -281,6 +281,7 @@ func (e *DataClockConsensusEngine) processFrame(
|
||||
},
|
||||
},
|
||||
},
|
||||
Timestamp: time.Now().UnixMilli(),
|
||||
})
|
||||
|
||||
if e.config.Engine.AutoMergeCoins {
|
||||
@ -321,6 +322,7 @@ func (e *DataClockConsensusEngine) processFrame(
|
||||
},
|
||||
},
|
||||
},
|
||||
Timestamp: time.Now().UnixMilli(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"time"
|
||||
|
||||
"github.com/libp2p/go-libp2p/core/peer"
|
||||
@ -59,7 +60,38 @@ func (e *DataClockConsensusEngine) validateTxMessage(peerID peer.ID, message *pb
|
||||
e.logger.Debug("could not unmarshal token request", zap.Error(err))
|
||||
return p2p.ValidationResultReject
|
||||
}
|
||||
// NOTE: There are no timestamps to be validated for token requests.
|
||||
if mint := tx.GetMint(); mint != nil {
|
||||
if len(mint.Proofs) < 3 {
|
||||
e.logger.Debug("mint request is missing proofs")
|
||||
return p2p.ValidationResultReject
|
||||
}
|
||||
if len(mint.Proofs[1]) != 4 {
|
||||
e.logger.Debug("mint request has invalid modulo")
|
||||
return p2p.ValidationResultReject
|
||||
}
|
||||
if len(mint.Proofs[2]) != 8 {
|
||||
e.logger.Debug("mint request has invalid frame number")
|
||||
return p2p.ValidationResultReject
|
||||
}
|
||||
head, err := e.dataTimeReel.Head()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if frameNumber := binary.BigEndian.Uint64(mint.Proofs[2]); frameNumber+10 < head.FrameNumber {
|
||||
e.logger.Debug("mint request is too old", zap.Uint64("frame_number", frameNumber))
|
||||
return p2p.ValidationResultIgnore
|
||||
}
|
||||
}
|
||||
if tx.Timestamp == 0 {
|
||||
// NOTE: The timestamp was added in later versions of the protocol,
|
||||
// and as such it is possible to receive requests without it.
|
||||
// We avoid logging due to this reason.
|
||||
return p2p.ValidationResultAccept
|
||||
}
|
||||
if ts := time.UnixMilli(tx.Timestamp); time.Since(ts) > 10*time.Minute {
|
||||
e.logger.Debug("token request is too old", zap.Time("timestamp", ts))
|
||||
return p2p.ValidationResultIgnore
|
||||
}
|
||||
return p2p.ValidationResultAccept
|
||||
default:
|
||||
e.logger.Debug("unknown message type", zap.String("type_url", a.TypeUrl))
|
||||
|
||||
@ -543,6 +543,7 @@ func (e *DataClockConsensusEngine) handleMint(
|
||||
},
|
||||
},
|
||||
},
|
||||
Timestamp: time.Now().UnixMilli(),
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
|
||||
@ -390,6 +390,7 @@ func NewTokenExecutionEngine(
|
||||
},
|
||||
},
|
||||
},
|
||||
Timestamp: gotime.Now().UnixMilli(),
|
||||
},
|
||||
)
|
||||
}
|
||||
@ -1371,6 +1372,7 @@ func (e *TokenExecutionEngine) AnnounceProverJoin() {
|
||||
Announce: e.AnnounceProverMerge(),
|
||||
},
|
||||
},
|
||||
Timestamp: gotime.Now().UnixMilli(),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -245,6 +245,7 @@ message TokenRequest {
|
||||
AnnounceProverPause pause = 8;
|
||||
AnnounceProverResume resume = 9;
|
||||
}
|
||||
int64 timestamp = 10;
|
||||
}
|
||||
|
||||
message TokenRequests {
|
||||
|
||||
@ -6,6 +6,7 @@ import (
|
||||
"math/big"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"source.quilibrium.com/quilibrium/monorepo/node/config"
|
||||
"source.quilibrium.com/quilibrium/monorepo/node/execution/intrinsics/token/application"
|
||||
@ -218,6 +219,8 @@ func (r *RPCServer) SendMessage(
|
||||
ctx context.Context,
|
||||
req *protobufs.TokenRequest,
|
||||
) (*protobufs.SendMessageResponse, error) {
|
||||
req.Timestamp = time.Now().UnixMilli()
|
||||
|
||||
any := &anypb.Any{}
|
||||
if err := any.MarshalFrom(req); err != nil {
|
||||
return nil, errors.Wrap(err, "publish message")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user