pre-payload
This commit is contained in:
parent
6b010bec73
commit
cac8d041eb
4
Makefile
4
Makefile
@ -65,7 +65,7 @@ integration-test-local-no-race:
|
|||||||
unit-test-local:
|
unit-test-local:
|
||||||
go vet ./...
|
go vet ./...
|
||||||
go fmt ./...
|
go fmt ./...
|
||||||
$(GINKGO) -r --label-filter unit \
|
$(GINKGO) -r --label-filter 'unit && !flaky' \
|
||||||
--randomize-all --randomize-suites \
|
--randomize-all --randomize-suites \
|
||||||
--flake-attempts=3 \
|
--flake-attempts=3 \
|
||||||
--fail-on-pending --keep-going \
|
--fail-on-pending --keep-going \
|
||||||
@ -109,4 +109,4 @@ build:
|
|||||||
## Build docker image
|
## Build docker image
|
||||||
.PHONY: docker-build
|
.PHONY: docker-build
|
||||||
docker-build:
|
docker-build:
|
||||||
docker build -t vulcanize/ipld-eth-beacon-indexer .
|
docker build -t vulcanize/ipld-eth-beacon-indexer .
|
||||||
|
@ -98,7 +98,7 @@ var _ = Describe("Capturehistoric", func() {
|
|||||||
BeaconNodeTester.runKnownGapsProcess(bc, 2, 2, 0, 2, 0)
|
BeaconNodeTester.runKnownGapsProcess(bc, 2, 2, 0, 2, 0)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
Context("When theres a reprocessing error", Label("reprocessingError"), func() {
|
Context("When theres a reprocessing error", Label("reprocessingError", "flaky"), func() {
|
||||||
It("Should update the reprocessing error.", func() {
|
It("Should update the reprocessing error.", func() {
|
||||||
bc := setUpTest(BeaconNodeTester.TestConfig, "99")
|
bc := setUpTest(BeaconNodeTester.TestConfig, "99")
|
||||||
BeaconNodeTester.SetupBeaconNodeMock(BeaconNodeTester.TestEvents, BeaconNodeTester.TestConfig.protocol, BeaconNodeTester.TestConfig.address, BeaconNodeTester.TestConfig.port, BeaconNodeTester.TestConfig.dummyParentRoot)
|
BeaconNodeTester.SetupBeaconNodeMock(BeaconNodeTester.TestEvents, BeaconNodeTester.TestConfig.protocol, BeaconNodeTester.TestConfig.address, BeaconNodeTester.TestConfig.port, BeaconNodeTester.TestConfig.dummyParentRoot)
|
||||||
|
@ -62,12 +62,17 @@ type DbSlots struct {
|
|||||||
|
|
||||||
// A struct to capture whats being written to eth-beacon.signed_block table.
|
// A struct to capture whats being written to eth-beacon.signed_block table.
|
||||||
type DbSignedBeaconBlock struct {
|
type DbSignedBeaconBlock struct {
|
||||||
Slot string // The slot.
|
Slot string // The slot.
|
||||||
BlockRoot string // The block root
|
BlockRoot string // The block root
|
||||||
ParentBlock string // The parent block root.
|
ParentBlock string // The parent block root.
|
||||||
Eth1DataBlockHash string // The eth1 block_hash
|
Eth1DataBlockHash string // The eth1 block_hash
|
||||||
MhKey string // The ipld multihash key.
|
MhKey string // The ipld multihash key.
|
||||||
|
PayloadBlockNumber int64
|
||||||
|
PayloadTimestamp int64
|
||||||
|
PayloadBlockHash string
|
||||||
|
PayloadParentHash string
|
||||||
|
PayloadStateRoot string
|
||||||
|
PayloadReceiptsRoot string
|
||||||
}
|
}
|
||||||
|
|
||||||
// A struct to capture whats being written to eth-beacon.state table.
|
// A struct to capture whats being written to eth-beacon.state table.
|
||||||
|
@ -191,7 +191,7 @@ func processFullSlot(
|
|||||||
}
|
}
|
||||||
|
|
||||||
parseBeaconTime := time.Now()
|
parseBeaconTime := time.Now()
|
||||||
finalBlockRoot, finalStateRoot, finalEth1DataBlockHash, err := ps.provideFinalHash()
|
finalBlockRoot, finalStateRoot, _, err := ps.provideFinalHash()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err, "CalculateBlockRoot"
|
return err, "CalculateBlockRoot"
|
||||||
}
|
}
|
||||||
@ -199,11 +199,25 @@ func processFullSlot(
|
|||||||
|
|
||||||
if spd.CheckDb {
|
if spd.CheckDb {
|
||||||
checkDbTime := time.Now()
|
checkDbTime := time.Now()
|
||||||
inDb, err := IsSlotInDb(ctx, ps.Db, strconv.Itoa(ps.Slot), finalBlockRoot, finalStateRoot)
|
var blockRequired bool
|
||||||
if err != nil {
|
if spd.PerformBeaconBlockProcessing {
|
||||||
return err, "checkDb"
|
blockExists, err := checkSlotAndRoot(ps.Db, CheckSignedBeaconBlockStmt, strconv.Itoa(ps.Slot), finalBlockRoot)
|
||||||
|
if err != nil {
|
||||||
|
return err, "checkDb"
|
||||||
|
}
|
||||||
|
blockRequired = !blockExists
|
||||||
}
|
}
|
||||||
if inDb {
|
|
||||||
|
var stateRequired bool
|
||||||
|
if spd.PerformBeaconStateProcessing {
|
||||||
|
stateExists, err := checkSlotAndRoot(ps.Db, CheckBeaconStateStmt, strconv.Itoa(ps.Slot), finalStateRoot)
|
||||||
|
if err != nil {
|
||||||
|
return err, "checkDb"
|
||||||
|
}
|
||||||
|
stateRequired = !stateExists
|
||||||
|
}
|
||||||
|
|
||||||
|
if !blockRequired && !stateRequired {
|
||||||
log.WithField("slot", slot).Info("Slot already in the DB.")
|
log.WithField("slot", slot).Info("Slot already in the DB.")
|
||||||
return nil, ""
|
return nil, ""
|
||||||
}
|
}
|
||||||
@ -212,7 +226,7 @@ func processFullSlot(
|
|||||||
|
|
||||||
// Get this object ready to write
|
// Get this object ready to write
|
||||||
createDbWriteTime := time.Now()
|
createDbWriteTime := time.Now()
|
||||||
dw, err := ps.createWriteObjects(finalBlockRoot, finalStateRoot, finalEth1DataBlockHash)
|
dw, err := ps.createWriteObjects()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err, "blockRoot"
|
return err, "blockRoot"
|
||||||
}
|
}
|
||||||
@ -303,6 +317,11 @@ func (ps *ProcessSlot) getSignedBeaconBlock(serverAddress string) error {
|
|||||||
ps.SszSignedBeaconBlock = []byte{}
|
ps.SszSignedBeaconBlock = []byte{}
|
||||||
ps.ParentBlockRoot = ""
|
ps.ParentBlockRoot = ""
|
||||||
ps.Status = "skipped"
|
ps.Status = "skipped"
|
||||||
|
|
||||||
|
// A 404 is normal in the case of a "skipped" slot.
|
||||||
|
if rc == 404 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -389,7 +408,7 @@ func (ps *ProcessSlot) checkPreviousSlot(tx sql.Tx, ctx context.Context, previou
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Transforms all the raw data into DB models that can be written to the DB.
|
// Transforms all the raw data into DB models that can be written to the DB.
|
||||||
func (ps *ProcessSlot) createWriteObjects(blockRoot, stateRoot, eth1DataBlockHash string) (*DatabaseWriter, error) {
|
func (ps *ProcessSlot) createWriteObjects() (*DatabaseWriter, error) {
|
||||||
var status string
|
var status string
|
||||||
if ps.Status != "" {
|
if ps.Status != "" {
|
||||||
status = ps.Status
|
status = ps.Status
|
||||||
@ -397,7 +416,15 @@ func (ps *ProcessSlot) createWriteObjects(blockRoot, stateRoot, eth1DataBlockHas
|
|||||||
status = "proposed"
|
status = "proposed"
|
||||||
}
|
}
|
||||||
|
|
||||||
dw, err := CreateDatabaseWrite(ps.Db, ps.Slot, stateRoot, blockRoot, ps.ParentBlockRoot, eth1DataBlockHash, status, &ps.SszSignedBeaconBlock, &ps.SszBeaconState, ps.Metrics)
|
parseBeaconTime := time.Now()
|
||||||
|
blockRoot, stateRoot, eth1DataBlockHash, err := ps.provideFinalHash()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
ps.PerformanceMetrics.ParseBeaconObjectForHash = time.Since(parseBeaconTime)
|
||||||
|
|
||||||
|
dw, err := CreateDatabaseWrite(ps.Db, ps.Slot, stateRoot, blockRoot, ps.ParentBlockRoot, eth1DataBlockHash,
|
||||||
|
status, &ps.SszSignedBeaconBlock, &ps.SszBeaconState, ps.Metrics)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return dw, err
|
return dw, err
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
package beaconclient
|
package beaconclient
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -53,47 +52,18 @@ func querySsz(endpoint string, slot string) ([]byte, int, error) {
|
|||||||
return nil, 0, fmt.Errorf("Unable to query Beacon Node: %s", err.Error())
|
return nil, 0, fmt.Errorf("Unable to query Beacon Node: %s", err.Error())
|
||||||
}
|
}
|
||||||
defer response.Body.Close()
|
defer response.Body.Close()
|
||||||
|
|
||||||
rc := response.StatusCode
|
rc := response.StatusCode
|
||||||
|
// Any 2xx code is OK.
|
||||||
|
if rc < 200 || rc >= 300 {
|
||||||
|
return nil, rc, fmt.Errorf("HTTP Error: %d", rc)
|
||||||
|
}
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(response.Body)
|
body, err := ioutil.ReadAll(response.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
loghelper.LogSlotError(slot, err).Error("Unable to turn response into a []bytes array!")
|
loghelper.LogSlotError(slot, err).Error("Unable to turn response into a []bytes array!")
|
||||||
return nil, rc, fmt.Errorf("Unable to turn response into a []bytes array!: %s", err.Error())
|
return nil, rc, fmt.Errorf("Unable to turn response into a []bytes array!: %s", err.Error())
|
||||||
}
|
}
|
||||||
if rc != 200 {
|
|
||||||
return body, rc, fmt.Errorf("HTTP Error: %d", rc)
|
|
||||||
}
|
|
||||||
return body, rc, nil
|
return body, rc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// A function to query the blockroot for a given slot.
|
|
||||||
func queryBlockRoot(endpoint string, slot string) (string, error) {
|
|
||||||
log.WithFields(log.Fields{"endpoint": endpoint}).Debug("Querying endpoint")
|
|
||||||
client := &http.Client{}
|
|
||||||
req, err := http.NewRequest("GET", endpoint, nil)
|
|
||||||
if err != nil {
|
|
||||||
loghelper.LogSlotError(slot, err).Error("Unable to create a request!")
|
|
||||||
return "", fmt.Errorf("Unable to create a request!: %s", err.Error())
|
|
||||||
}
|
|
||||||
req.Header.Set("Accept", "application/json")
|
|
||||||
response, err := client.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
loghelper.LogSlotError(slot, err).Error("Unable to query Beacon Node!")
|
|
||||||
return "", fmt.Errorf("Unable to query Beacon Node: %s", err.Error())
|
|
||||||
}
|
|
||||||
defer response.Body.Close()
|
|
||||||
body, err := ioutil.ReadAll(response.Body)
|
|
||||||
if err != nil {
|
|
||||||
loghelper.LogSlotError(slot, err).Error("Unable to turn response into a []bytes array!")
|
|
||||||
return "", fmt.Errorf("Unable to turn response into a []bytes array!: %s", err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := BlockRootResponse{}
|
|
||||||
if err := json.Unmarshal(body, &resp); err != nil {
|
|
||||||
loghelper.LogEndpoint(endpoint).WithFields(log.Fields{
|
|
||||||
"rawMessage": string(body),
|
|
||||||
"err": err,
|
|
||||||
}).Error("Unable to unmarshal the block root")
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return resp.Data.Root, nil
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user