revisions

This commit is contained in:
Roy Crihfield 2022-02-16 19:27:02 +08:00
parent 3fda647ee9
commit ef4ae3a0d4
2 changed files with 17 additions and 20 deletions

View File

@ -77,10 +77,7 @@ type fileWriter struct {
// fileWriters wraps the file writers for each output table // fileWriters wraps the file writers for each output table
type fileWriters map[*snapt.Table]fileWriter type fileWriters map[*snapt.Table]fileWriter
type fileTx struct { type fileTx struct{ fileWriters }
fileWriters
// index uint
}
func (tx fileWriters) Commit() error { func (tx fileWriters) Commit() error {
for _, w := range tx { for _, w := range tx {
@ -209,13 +206,13 @@ func (p *publisher) PublishHeader(header *types.Header) error {
// PublishStateNode writes the state node to the ipfs backing datastore and adds secondary indexes // PublishStateNode writes the state node to the ipfs backing datastore and adds secondary indexes
// in the state_cids table // in the state_cids table
func (p *publisher) PublishStateNode(node *snapt.Node, headerID string, tx_ snapt.Tx) error { func (p *publisher) PublishStateNode(node *snapt.Node, headerID string, snapTx snapt.Tx) error {
var stateKey string var stateKey string
if !snapt.IsNullHash(node.Key) { if !snapt.IsNullHash(node.Key) {
stateKey = node.Key.Hex() stateKey = node.Key.Hex()
} }
tx := tx_.(fileTx) tx := snapTx.(fileTx)
stateCIDStr, mhKey, err := tx.publishRaw(ipld.MEthStateTrie, node.Value) stateCIDStr, mhKey, err := tx.publishRaw(ipld.MEthStateTrie, node.Value)
if err != nil { if err != nil {
return err return err
@ -235,13 +232,13 @@ func (p *publisher) PublishStateNode(node *snapt.Node, headerID string, tx_ snap
// PublishStorageNode writes the storage node to the ipfs backing pg datastore and adds secondary // PublishStorageNode writes the storage node to the ipfs backing pg datastore and adds secondary
// indexes in the storage_cids table // indexes in the storage_cids table
func (p *publisher) PublishStorageNode(node *snapt.Node, headerID string, statePath []byte, tx_ snapt.Tx) error { func (p *publisher) PublishStorageNode(node *snapt.Node, headerID string, statePath []byte, snapTx snapt.Tx) error {
var storageKey string var storageKey string
if !snapt.IsNullHash(node.Key) { if !snapt.IsNullHash(node.Key) {
storageKey = node.Key.Hex() storageKey = node.Key.Hex()
} }
tx := tx_.(fileTx) tx := snapTx.(fileTx)
storageCIDStr, mhKey, err := tx.publishRaw(ipld.MEthStorageTrie, node.Value) storageCIDStr, mhKey, err := tx.publishRaw(ipld.MEthStorageTrie, node.Value)
if err != nil { if err != nil {
return err return err
@ -260,14 +257,14 @@ func (p *publisher) PublishStorageNode(node *snapt.Node, headerID string, stateP
} }
// PublishCode writes code to the ipfs backing pg datastore // PublishCode writes code to the ipfs backing pg datastore
func (p *publisher) PublishCode(codeHash common.Hash, codeBytes []byte, tx_ snapt.Tx) error { func (p *publisher) PublishCode(codeHash common.Hash, codeBytes []byte, snapTx snapt.Tx) error {
// no codec for code, doesn't matter though since blockstore key is multihash-derived // no codec for code, doesn't matter though since blockstore key is multihash-derived
mhKey, err := shared.MultihashKeyFromKeccak256(codeHash) mhKey, err := shared.MultihashKeyFromKeccak256(codeHash)
if err != nil { if err != nil {
return fmt.Errorf("error deriving multihash key from codehash: %v", err) return fmt.Errorf("error deriving multihash key from codehash: %v", err)
} }
tx := tx_.(fileTx) tx := snapTx.(fileTx)
if err = tx.write(&snapt.TableIPLDBlock, mhKey, codeBytes); err != nil { if err = tx.write(&snapt.TableIPLDBlock, mhKey, codeBytes); err != nil {
return fmt.Errorf("error publishing code IPLD: %v", err) return fmt.Errorf("error publishing code IPLD: %v", err)
} }

View File

@ -112,11 +112,11 @@ func (p *publisher) PublishHeader(header *types.Header) (err error) {
return err return err
} }
tx_, err := p.db.Begin(context.Background()) snapTx, err := p.db.Begin(context.Background())
if err != nil { if err != nil {
return err return err
} }
tx := pubTx{tx_, nil} tx := pubTx{snapTx, nil}
defer func() { err = snapt.CommitOrRollback(tx, err) }() defer func() { err = snapt.CommitOrRollback(tx, err) }()
if _, err = tx.publishIPLD(headerNode.Cid(), headerNode.RawData()); err != nil { if _, err = tx.publishIPLD(headerNode.Cid(), headerNode.RawData()); err != nil {
@ -132,13 +132,13 @@ func (p *publisher) PublishHeader(header *types.Header) (err error) {
} }
// PublishStateNode writes the state node to the ipfs backing datastore and adds secondary indexes in the state_cids table // PublishStateNode writes the state node to the ipfs backing datastore and adds secondary indexes in the state_cids table
func (p *publisher) PublishStateNode(node *snapt.Node, headerID string, tx_ snapt.Tx) error { func (p *publisher) PublishStateNode(node *snapt.Node, headerID string, snapTx snapt.Tx) error {
var stateKey string var stateKey string
if !snapt.IsNullHash(node.Key) { if !snapt.IsNullHash(node.Key) {
stateKey = node.Key.Hex() stateKey = node.Key.Hex()
} }
tx := tx_.(pubTx) tx := snapTx.(pubTx)
stateCIDStr, mhKey, err := tx.publishRaw(ipld.MEthStateTrie, node.Value) stateCIDStr, mhKey, err := tx.publishRaw(ipld.MEthStateTrie, node.Value)
if err != nil { if err != nil {
return err return err
@ -158,13 +158,13 @@ func (p *publisher) PublishStateNode(node *snapt.Node, headerID string, tx_ snap
} }
// PublishStorageNode writes the storage node to the ipfs backing pg datastore and adds secondary indexes in the storage_cids table // PublishStorageNode writes the storage node to the ipfs backing pg datastore and adds secondary indexes in the storage_cids table
func (p *publisher) PublishStorageNode(node *snapt.Node, headerID string, statePath []byte, tx_ snapt.Tx) error { func (p *publisher) PublishStorageNode(node *snapt.Node, headerID string, statePath []byte, snapTx snapt.Tx) error {
var storageKey string var storageKey string
if !snapt.IsNullHash(node.Key) { if !snapt.IsNullHash(node.Key) {
storageKey = node.Key.Hex() storageKey = node.Key.Hex()
} }
tx := tx_.(pubTx) tx := snapTx.(pubTx)
storageCIDStr, mhKey, err := tx.publishRaw(ipld.MEthStorageTrie, node.Value) storageCIDStr, mhKey, err := tx.publishRaw(ipld.MEthStorageTrie, node.Value)
if err != nil { if err != nil {
return err return err
@ -184,14 +184,14 @@ func (p *publisher) PublishStorageNode(node *snapt.Node, headerID string, stateP
} }
// PublishCode writes code to the ipfs backing pg datastore // PublishCode writes code to the ipfs backing pg datastore
func (p *publisher) PublishCode(codeHash common.Hash, codeBytes []byte, tx_ snapt.Tx) error { func (p *publisher) PublishCode(codeHash common.Hash, codeBytes []byte, snapTx snapt.Tx) error {
// no codec for code, doesn't matter though since blockstore key is multihash-derived // no codec for code, doesn't matter though since blockstore key is multihash-derived
mhKey, err := shared.MultihashKeyFromKeccak256(codeHash) mhKey, err := shared.MultihashKeyFromKeccak256(codeHash)
if err != nil { if err != nil {
return fmt.Errorf("error deriving multihash key from codehash: %v", err) return fmt.Errorf("error deriving multihash key from codehash: %v", err)
} }
tx := tx_.(pubTx) tx := snapTx.(pubTx)
if _, err = tx.Exec(snapt.TableIPLDBlock.ToInsertStatement(), mhKey, codeBytes); err != nil { if _, err = tx.Exec(snapt.TableIPLDBlock.ToInsertStatement(), mhKey, codeBytes); err != nil {
return fmt.Errorf("error publishing code IPLD: %v", err) return fmt.Errorf("error publishing code IPLD: %v", err)
} }
@ -211,8 +211,8 @@ func (p *publisher) PrepareTxForBatch(tx snapt.Tx, maxBatchSize uint) (snapt.Tx,
return nil, err return nil, err
} }
tx_, err := p.db.Begin(context.Background()) snapTx, err := p.db.Begin(context.Background())
tx = pubTx{Tx: tx_} tx = pubTx{Tx: snapTx}
if err != nil { if err != nil {
return nil, err return nil, err
} }