arnaucube
arnaucube/hermez-nodePublic Self-hosted repository
hermez-node/coordinator/batch.go
coordinator/batch.goRaw
 1package coordinator
 2
 3import (
 4	"encoding/json"
 5	"fmt"
 6	"io/ioutil"
 7	"math/big"
 8	"path"
 9
10	"github.com/ethereum/go-ethereum/core/types"
11	"github.com/hermeznetwork/hermez-node/common"
12	"github.com/hermeznetwork/hermez-node/eth"
13	"github.com/hermeznetwork/hermez-node/prover"
14	"github.com/hermeznetwork/tracerr"
15)
16
17// Status is used to mark the status of the batch
18type Status string
19
20const (
21	// StatusPending marks the Tx as Pending
22	StatusPending Status = "pending"
23	// StatusForged marks the batch as forged internally
24	StatusForged Status = "forged"
25	// StatusProof marks the batch as proof calculated
26	StatusProof Status = "proof"
27	// StatusSent marks the EthTx as Sent
28	StatusSent Status = "sent"
29	// StatusMined marks the EthTx as Mined
30	StatusMined Status = "mined"
31	// StatusFailed marks the EthTx as Failed
32	StatusFailed Status = "failed"
33)
34
35// BatchInfo contans the Batch information
36type BatchInfo struct {
37	BatchNum              common.BatchNum
38	ServerProof           prover.Client
39	ZKInputs              *common.ZKInputs
40	Proof                 *prover.Proof
41	PublicInputs          []*big.Int
42	L1Batch               bool
43	VerifierIdx           uint8
44	L1UserTxsExtra        []common.L1Tx
45	L1CoordTxs            []common.L1Tx
46	L1CoordinatorTxsAuths [][]byte
47	L2Txs                 []common.L2Tx
48	CoordIdxs             []common.Idx
49	ForgeBatchArgs        *eth.RollupForgeBatchArgs
50	// FeesInfo
51	Status  Status
52	EthTx   *types.Transaction
53	Receipt *types.Receipt
54}
55
56// DebugStore is a debug function to store the BatchInfo as a json text file in
57// storePath
58func (b *BatchInfo) DebugStore(storePath string) error {
59	batchJSON, err := json.MarshalIndent(b, "", "  ")
60	if err != nil {
61		return tracerr.Wrap(err)
62	}
63	oldStateRoot := "null"
64	if b.ZKInputs != nil && b.ZKInputs.OldStateRoot != nil {
65		oldStateRoot = b.ZKInputs.OldStateRoot.String()
66	}
67	filename := fmt.Sprintf("%010d-%s.json", b.BatchNum, oldStateRoot)
68	// nolint reason: 0640 allows rw to owner and r to group
69	//nolint:gosec
70	return ioutil.WriteFile(path.Join(storePath, filename), batchJSON, 0640)
71}