Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

Commit

Permalink
Rename some fields to better fit in with new SUBMITTED status (#565)
Browse files Browse the repository at this point in the history
* Rename SubmissionBlock->MinedBlock in dto.Batch

* Rename SubmissionTime->MinedTime in dto.Batch

* Rename SubmissionTime->MinedTime in models.Batch

* Rename SubmissionTime->MinedTime in stored.Batch

* Rename SubmissionTime->MinedTime in DecodedBatchBase

* Rename getSubmissionBlock->getMinedBlock

* Rename variable

* Rename BatchTime->MinedTime

* Update json_rpc.md

* Rename SubmissionTime in data_structures.md

Co-authored-by: Bartlomiej Tarczynski <bartlomiej.tarczynski1@gmail.com>
Co-authored-by: Bartlomiej Tarczynski <51199571+b-tarczynski@users.noreply.github.com>
  • Loading branch information
3 people authored Feb 3, 2022
1 parent 96d83b4 commit 1d73448
Show file tree
Hide file tree
Showing 23 changed files with 131 additions and 131 deletions.
2 changes: 1 addition & 1 deletion api/admin/get_pending_batches_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (s *GetPendingBatchesTestSuite) SetupTest() {
TransactionHash: utils.RandomHash(),
Hash: utils.NewRandomHash(),
FinalisationBlock: ref.Uint32(42000),
SubmissionTime: models.NewTimestamp(time.Unix(140, 0).UTC()),
MinedTime: models.NewTimestamp(time.Unix(140, 0).UTC()),
},
{
ID: models.MakeUint256(2),
Expand Down
34 changes: 17 additions & 17 deletions api/get_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ func (a *API) unsafeGetBatchByID(id models.Uint256) (*dto.BatchWithRootAndCommit
}

func (a *API) getCommitmentsAndCreateBatchDTO(batch *models.Batch) (*dto.BatchWithRootAndCommitments, error) {
submissionBlock, err := a.getSubmissionBlock(batch)
minedBlock, err := a.getMinedBlock(batch)
if err != nil {
return nil, err
}

if batch.Type == batchtype.Genesis {
return a.createBatchWithCommitments(batch, submissionBlock, batchstatus.Finalised.Ref(), nil)
return a.createBatchWithCommitments(batch, minedBlock, batchstatus.Finalised.Ref(), nil)
}

status := calculateBatchStatus(a.storage.GetLatestBlockNumber(), batch)
Expand All @@ -67,30 +67,30 @@ func (a *API) getCommitmentsAndCreateBatchDTO(batch *models.Batch) (*dto.BatchWi
return nil, err
}

return a.createBatchWithCommitments(batch, submissionBlock, status, commitments)
return a.createBatchWithCommitments(batch, minedBlock, status, commitments)
}

func (a *API) createBatchWithCommitments(
batch *models.Batch,
submissionBlock *uint32,
minedBlock *uint32,
status *batchstatus.BatchStatus,
commitments []models.Commitment,
) (*dto.BatchWithRootAndCommitments, error) {
switch batch.Type {
case batchtype.Transfer, batchtype.Create2Transfer:
return a.createBatchWithTxCommitments(batch, submissionBlock, status, commitments)
return a.createBatchWithTxCommitments(batch, minedBlock, status, commitments)
case batchtype.MassMigration:
return a.createBatchWithMMCommitments(batch, submissionBlock, status, commitments)
return a.createBatchWithMMCommitments(batch, minedBlock, status, commitments)
case batchtype.Deposit:
return a.createBatchWithDepositCommitments(batch, submissionBlock, status, commitments)
return a.createBatchWithDepositCommitments(batch, minedBlock, status, commitments)
default:
return dto.MakeBatchWithRootAndCommitments(dto.NewBatch(batch, submissionBlock, status), batch.AccountTreeRoot, nil), nil
return dto.MakeBatchWithRootAndCommitments(dto.NewBatch(batch, minedBlock, status), batch.AccountTreeRoot, nil), nil
}
}

func (a *API) createBatchWithTxCommitments(
batch *models.Batch,
submissionBlock *uint32,
minedBlock *uint32,
status *batchstatus.BatchStatus,
commitments []models.Commitment,
) (*dto.BatchWithRootAndCommitments, error) {
Expand All @@ -106,12 +106,12 @@ func (a *API) createBatchWithTxCommitments(
stateLeaf.TokenID,
))
}
return createBatchWithRootAndCommitmentsDTO(batch, submissionBlock, status, batchCommitments), nil
return createBatchWithRootAndCommitmentsDTO(batch, minedBlock, status, batchCommitments), nil
}

func (a *API) createBatchWithMMCommitments(
batch *models.Batch,
submissionBlock *uint32,
minedBlock *uint32,
status *batchstatus.BatchStatus,
commitments []models.Commitment,
) (*dto.BatchWithRootAndCommitments, error) {
Expand All @@ -121,12 +121,12 @@ func (a *API) createBatchWithMMCommitments(
commitments[i].ToMMCommitment(),
))
}
return createBatchWithRootAndCommitmentsDTO(batch, submissionBlock, status, batchCommitments), nil
return createBatchWithRootAndCommitmentsDTO(batch, minedBlock, status, batchCommitments), nil
}

func (a *API) createBatchWithDepositCommitments(
batch *models.Batch,
submissionBlock *uint32,
minedBlock *uint32,
status *batchstatus.BatchStatus,
commitments []models.Commitment,
) (*dto.BatchWithRootAndCommitments, error) {
Expand All @@ -136,10 +136,10 @@ func (a *API) createBatchWithDepositCommitments(
commitments[i].ToDepositCommitment(),
))
}
return createBatchWithRootAndCommitmentsDTO(batch, submissionBlock, status, batchCommitments), nil
return createBatchWithRootAndCommitmentsDTO(batch, minedBlock, status, batchCommitments), nil
}

func (a *API) getSubmissionBlock(batch *models.Batch) (*uint32, error) {
func (a *API) getMinedBlock(batch *models.Batch) (*uint32, error) {
if batch.ID.IsZero() {
return batch.FinalisationBlock, nil
}
Expand Down Expand Up @@ -170,7 +170,7 @@ func calculateBatchStatus(latestBlockNumber uint32, batch *models.Batch) *batchs

func createBatchWithRootAndCommitmentsDTO(
batch *models.Batch,
submissionBlock *uint32,
minedBlock *uint32,
status *batchstatus.BatchStatus,
commitments interface{},
) *dto.BatchWithRootAndCommitments {
Expand All @@ -183,7 +183,7 @@ func createBatchWithRootAndCommitmentsDTO(
}

return dto.MakeBatchWithRootAndCommitments(
dto.NewBatch(batch, submissionBlock, status),
dto.NewBatch(batch, minedBlock, status),
batch.AccountTreeRoot,
commitments,
)
Expand Down
18 changes: 9 additions & 9 deletions api/get_batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (s *GetBatchTestSuite) SetupTest() {
Hash: utils.NewRandomHash(),
FinalisationBlock: ref.Uint32(42000),
AccountTreeRoot: utils.NewRandomHash(),
SubmissionTime: models.NewTimestamp(time.Unix(140, 0).UTC()),
MinedTime: models.NewTimestamp(time.Unix(140, 0).UTC()),
}

s.txCommitment = &models.TxCommitment{
Expand Down Expand Up @@ -186,7 +186,7 @@ func (s *GetBatchTestSuite) TestGetBatchByHash_GenesisBatch() {
s.NoError(err)
s.Equal(genesisBatch.Hash, result.Hash)
s.Equal(genesisBatch.Type, result.Type)
s.Equal(*genesisBatch.FinalisationBlock, *result.SubmissionBlock)
s.Equal(*genesisBatch.FinalisationBlock, *result.MinedBlock)
s.Nil(result.Commitments)
}

Expand Down Expand Up @@ -260,7 +260,7 @@ func (s *GetBatchTestSuite) TestGetBatchByID_GenesisBatch() {
s.NoError(err)
s.Equal(genesisBatch.Hash, result.Hash)
s.Equal(genesisBatch.Type, result.Type)
s.Equal(*genesisBatch.FinalisationBlock, *result.SubmissionBlock)
s.Equal(*genesisBatch.FinalisationBlock, *result.MinedBlock)
s.Nil(result.Commitments)
}

Expand Down Expand Up @@ -337,20 +337,20 @@ func (s *GetBatchTestSuite) addSubmittedBatch(batchType batchtype.BatchType) {
pendingBatch.Type = batchType
pendingBatch.Hash = nil
pendingBatch.FinalisationBlock = nil
pendingBatch.SubmissionTime = nil
pendingBatch.MinedTime = nil
err := s.storage.AddBatch(&pendingBatch)
s.NoError(err)
}

func (s *GetBatchTestSuite) validateBatch(result *dto.BatchWithRootAndCommitments, batchType batchtype.BatchType) {
submissionBlock := *s.batch.FinalisationBlock - config.DefaultBlocksToFinalise
minedBlock := *s.batch.FinalisationBlock - config.DefaultBlocksToFinalise
expectedBatch := dto.Batch{
ID: s.batch.ID,
Hash: s.batch.Hash,
Type: batchType,
TransactionHash: s.batch.TransactionHash,
SubmissionBlock: &submissionBlock,
SubmissionTime: s.batch.SubmissionTime,
MinedBlock: &minedBlock,
MinedTime: s.batch.MinedTime,
Status: batchstatus.Mined,
FinalisationBlock: s.batch.FinalisationBlock,
}
Expand All @@ -364,8 +364,8 @@ func (s *GetBatchTestSuite) validateSubmittedBatch(result *dto.BatchWithRootAndC
Hash: nil,
Type: batchType,
TransactionHash: s.batch.TransactionHash,
SubmissionBlock: nil,
SubmissionTime: nil,
MinedBlock: nil,
MinedTime: nil,
Status: batchstatus.Submitted,
FinalisationBlock: nil,
}
Expand Down
10 changes: 5 additions & 5 deletions api/get_batches.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ func (a *API) unsafeGetBatches(from, to *models.Uint256) ([]dto.Batch, error) {
return []dto.Batch{}, err
}

batchesWithSubmission := make([]dto.Batch, 0, len(batches))
dtoBatches := make([]dto.Batch, 0, len(batches))
for i := range batches {
status := calculateBatchStatus(a.storage.GetLatestBlockNumber(), &batches[i])

if *status == batchstatus.Submitted {
batchesWithSubmission = append(batchesWithSubmission, *dto.NewSubmittedBatch(&batches[i]))
dtoBatches = append(dtoBatches, *dto.NewSubmittedBatch(&batches[i]))
} else {
submissionBlock, err := a.getSubmissionBlock(&batches[i])
minedBlock, err := a.getMinedBlock(&batches[i])
if err != nil {
return nil, err
}

batchesWithSubmission = append(batchesWithSubmission, *dto.NewBatch(&batches[i], submissionBlock, status))
dtoBatches = append(dtoBatches, *dto.NewBatch(&batches[i], minedBlock, status))
}
}
return batchesWithSubmission, nil
return dtoBatches, nil
}
22 changes: 11 additions & 11 deletions api/get_batches_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,31 +52,31 @@ func (s *GetBatchesTestSuite) SetupTest() {
TransactionHash: utils.RandomHash(),
Hash: utils.NewRandomHash(),
FinalisationBlock: ref.Uint32(42000),
SubmissionTime: models.NewTimestamp(time.Unix(140, 0).UTC()),
MinedTime: models.NewTimestamp(time.Unix(140, 0).UTC()),
},
{
ID: models.MakeUint256(2),
Type: batchtype.Create2Transfer,
TransactionHash: utils.RandomHash(),
Hash: utils.NewRandomHash(),
FinalisationBlock: ref.Uint32(43000),
SubmissionTime: models.NewTimestamp(time.Unix(150, 0).UTC()),
MinedTime: models.NewTimestamp(time.Unix(150, 0).UTC()),
},
{
ID: models.MakeUint256(3),
Type: batchtype.MassMigration,
TransactionHash: utils.RandomHash(),
Hash: utils.NewRandomHash(),
FinalisationBlock: ref.Uint32(44000),
SubmissionTime: models.NewTimestamp(time.Unix(160, 0).UTC()),
MinedTime: models.NewTimestamp(time.Unix(160, 0).UTC()),
},
{
ID: models.MakeUint256(4),
Type: batchtype.Deposit,
TransactionHash: utils.RandomHash(),
Hash: utils.NewRandomHash(),
FinalisationBlock: ref.Uint32(44000),
SubmissionTime: models.NewTimestamp(time.Unix(160, 0).UTC()),
MinedTime: models.NewTimestamp(time.Unix(160, 0).UTC()),
},
}
}
Expand All @@ -100,15 +100,15 @@ func (s *GetBatchesTestSuite) TestGetBatches() {
s.Equal(s.batches[i].Hash, result[i].Hash)
s.Equal(s.batches[i].Type, result[i].Type)
s.Equal(s.batches[i].TransactionHash, result[i].TransactionHash)
s.Equal(s.batches[i].SubmissionTime, result[i].SubmissionTime)
s.Equal(s.batches[i].MinedTime, result[i].MinedTime)
s.Equal(batchstatus.Mined, result[i].Status)
s.Equal(s.batches[i].FinalisationBlock, result[i].FinalisationBlock)
s.NotZero(result[i].SubmissionBlock)
s.NotZero(result[i].MinedBlock)

if s.batches[i].Type == batchtype.Genesis {
s.Equal(*s.batches[i].FinalisationBlock, *result[i].SubmissionBlock)
s.Equal(*s.batches[i].FinalisationBlock, *result[i].MinedBlock)
} else {
s.Equal(*s.batches[i].FinalisationBlock-config.DefaultBlocksToFinalise, *result[i].SubmissionBlock)
s.Equal(*s.batches[i].FinalisationBlock-config.DefaultBlocksToFinalise, *result[i].MinedBlock)
}
}
}
Expand All @@ -117,16 +117,16 @@ func (s *GetBatchesTestSuite) TestGetBatches_SubmittedBatch() {
pendingBatch := s.batches[1]
pendingBatch.Hash = nil
pendingBatch.FinalisationBlock = nil
pendingBatch.SubmissionTime = nil
pendingBatch.MinedTime = nil
err := s.storage.AddBatch(&pendingBatch)
s.NoError(err)

expectedBatch := dto.Batch{
ID: pendingBatch.ID,
Type: batchtype.Transfer,
TransactionHash: pendingBatch.TransactionHash,
SubmissionBlock: nil,
SubmissionTime: nil,
MinedBlock: nil,
MinedTime: nil,
Status: batchstatus.Submitted,
FinalisationBlock: nil,
}
Expand Down
6 changes: 3 additions & 3 deletions api/get_commitment.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ func (a *API) createCommitmentDTO(commitment models.Commitment, batch *models.Ba
case batchtype.Transfer, batchtype.Create2Transfer:
return a.createTxCommitmentDTO(commitment, batch, transactions, status)
case batchtype.MassMigration:
return dto.NewMMCommitment(commitment.ToMMCommitment(), status, batch.SubmissionTime, transactions), nil
return dto.NewMMCommitment(commitment.ToMMCommitment(), status, batch.MinedTime, transactions), nil
case batchtype.Deposit:
return dto.NewDepositCommitment(commitment.ToDepositCommitment(), status, batch.SubmissionTime), nil
return dto.NewDepositCommitment(commitment.ToDepositCommitment(), status, batch.MinedTime), nil
default:
panic("invalid commitment type")
}
Expand Down Expand Up @@ -122,7 +122,7 @@ func (a *API) createTxCommitmentDTO(
return nil, err
}

commitmentDTO := dto.NewTxCommitment(commitment.ToTxCommitment(), stateLeaf.TokenID, status, batch.SubmissionTime, transactions)
commitmentDTO := dto.NewTxCommitment(commitment.ToTxCommitment(), stateLeaf.TokenID, status, batch.MinedTime, transactions)

return commitmentDTO, nil
}
2 changes: 1 addition & 1 deletion api/get_commitment_proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (s *GetCommitmentProofTestSuite) SetupTest() {
TransactionHash: utils.RandomHash(),
Hash: utils.NewRandomHash(),
FinalisationBlock: ref.Uint32(113),
SubmissionTime: models.NewTimestamp(time.Unix(140, 0).UTC()),
MinedTime: models.NewTimestamp(time.Unix(140, 0).UTC()),
AccountTreeRoot: utils.NewRandomHash(),
}

Expand Down
Loading

0 comments on commit 1d73448

Please sign in to comment.