Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/v2-endpoints' into v2-endpoints
Browse files Browse the repository at this point in the history
# Conflicts:
#	validator/txstatus/models.go
#	validator/txstatus/models_test.go
#	validator/txstatus/validator.go
  • Loading branch information
LINCKODE committed Jul 1, 2024
2 parents 42d7841 + 6b28a2a commit 24ea860
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 44 deletions.
2 changes: 1 addition & 1 deletion dev.docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ services:
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.web.address=:80"
ports:
- "80:80"
- "8009:80"
- "127.0.0.1:8081:8080"
depends_on:
- "qubic-archiver"
Expand Down
32 changes: 1 addition & 31 deletions validator/txstatus/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,16 @@ import (
"github.com/pkg/errors"
"github.com/qubic/go-archiver/protobuff"
"github.com/qubic/go-node-connector/types"
"log"
)

func qubicToProto(txs types.Transactions, model types.TransactionStatus) (*protobuff.TickTransactionsStatus, error) {
func qubicToProto(model types.TransactionStatus) (*protobuff.TickTransactionsStatus, error) {
tickTransactions := make([]*protobuff.TransactionStatus, 0, model.TxCount)
txsIdMap, err := createTxsIdMap(txs)
if err != nil {
return nil, errors.Wrap(err, "error creating txs id map")
}

for index, txDigest := range model.TransactionDigests {
var id types.Identity
id, err := id.FromPubKey(txDigest, true)
if err != nil {
return nil, errors.Wrap(err, "converting digest to id")
}
if _, ok := txsIdMap[id.String()]; !ok {
log.Printf("Skipping tx status with id: %s\n", id.String())
continue
}

moneyFlew := getMoneyFlewFromBits(model.MoneyFlew, index)

tx := &protobuff.TransactionStatus{
Expand All @@ -38,25 +27,6 @@ func qubicToProto(txs types.Transactions, model types.TransactionStatus) (*proto
return &protobuff.TickTransactionsStatus{Transactions: tickTransactions}, nil
}

func createTxsIdMap(txs types.Transactions) (map[string]struct{}, error) {
txsIdMap := make(map[string]struct{}, len(txs))
for _, tx := range txs {
digest, err := tx.Digest()
if err != nil {
return nil, errors.Wrapf(err, "creating tx digest for tx with src pubkey %s", tx.SourcePublicKey)
}

id, err := tx.ID()
if err != nil {
return nil, errors.Wrapf(err, "converting tx with digest %s to id", digest)
}

txsIdMap[id] = struct{}{}
}

return txsIdMap, nil
}

func getMoneyFlewFromBits(input [(types.NumberOfTransactionsPerTick + 7) / 8]byte, digestIndex int) bool {
pos := digestIndex / 8
bitIndex := digestIndex % 8
Expand Down
2 changes: 1 addition & 1 deletion validator/txstatus/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestQubicToProto(t *testing.T) {
},
}

res, err := qubicToProto(types.Transactions{}, tickTransactionStatus)
res, err := qubicToProto(tickTransactionStatus)
if err != nil {
t.Fatalf("Got err when converting qubic to proto. err: %s", err.Error())
}
Expand Down
22 changes: 11 additions & 11 deletions validator/txstatus/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ import (
)

func Validate(ctx context.Context, tickTxStatus types.TransactionStatus, tickTxs types.Transactions) (*protobuff.TickTransactionsStatus, error) {
//if tickTxStatus.TxCount != uint32(len(tickTxs)) {
// return nil, errors.Errorf("Mismatched tx length. Tick tx status count: %d - len(tickTx): %d", tickTxStatus.TxCount, len(tickTxs))
//}
if tickTxStatus.TxCount != uint32(len(tickTxs)) {
return nil, errors.Errorf("Mismatched tx length. Tick tx status count: %d - len(tickTx): %d", tickTxStatus.TxCount, len(tickTxs))
}

//tickTxDigests, err := getTickTxDigests(tickTxs)
//if err != nil {
// return nil, errors.Wrap(err, "getting tick tx digests")
//}
tickTxDigests, err := getTickTxDigests(tickTxs)
if err != nil {
return nil, errors.Wrap(err, "getting tick tx digests")
}

//if !equalDigests(tickTxDigests, tickTxStatus.TransactionDigests) {
// return nil, errors.New("digests not equal")
//}
if !equalDigests(tickTxDigests, tickTxStatus.TransactionDigests) {
return nil, errors.New("digests not equal")
}

proto, err := qubicToProto(tickTxs, tickTxStatus)
proto, err := qubicToProto(tickTxStatus)
if err != nil {
return nil, errors.Wrap(err, "qubic to proto")
}
Expand Down

0 comments on commit 24ea860

Please sign in to comment.