Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log.Warns to debug weird issue #1390

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,15 @@ jobs:
with:
image-tag: ${{ github.ref_name }}

immediate-docker-release:
name: Docker (immediate)
if: github.event_name == 'pull_request' &&
github.base_ref == 'release-lts-1' # these pull requests trigger a release via a quicker workflow which skips the tests
uses: vocdoni/vocdoni-node/.github/workflows/docker-release.yml@main
secrets: inherit
with:
image-tag: ${{ github.head_ref }}

job_gocoverage_textfmt:
name: Convert coverage (bin->txt)
continue-on-error: true # never mark the whole CI as failed because of this job
Expand Down
8 changes: 7 additions & 1 deletion api/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,14 @@ func (a *API) accountSetHandler(msg *apirest.APIdata, ctx *httprouter.HTTPContex
}
}

log.Warn("pre sendTx")

// send the transaction to the blockchain
res, err := a.sendTx(req.TxPayload)
if err != nil {
return err
}
log.Warn("post sendTx")

// prepare the reply
resp := &AccountSet{
Expand All @@ -304,17 +307,20 @@ func (a *API) accountSetHandler(msg *apirest.APIdata, ctx *httprouter.HTTPContex
if a.storage != nil && req.Metadata != nil {
sctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
log.Warn("pre Publish")
cid, err := a.storage.Publish(sctx, req.Metadata)
if err != nil {
log.Errorf("could not publish to storage: %v", err)
} else {
resp.MetadataURL = a.storage.URIprefix() + cid
}
log.Warnf("post Publish, metadata: %s", resp.MetadataURL)

if !ipfs.CIDequals(cid, metadataCID) {
log.Errorf("metadata CID does not match metadata content (%s != %s)", cid, metadataCID)
}
}

log.Warn("pre Marshal")
var data []byte
if data, err = json.Marshal(resp); err != nil {
return err
Expand Down
65 changes: 55 additions & 10 deletions api/censuses.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const (
MaxCensusAddBatchSize = 8192

censusIDsize = 32
censusRetrieveTimeout = 5 * time.Minute
censusRetrieveTimeout = 10 * time.Minute
)

func (a *API) enableCensusHandlers() error {
Expand Down Expand Up @@ -170,6 +170,14 @@ func (a *API) enableCensusHandlers() error {
); err != nil {
return err
}
if err := a.Endpoint.RegisterMethod(
"/censuses/export/ipfs/list",
"GET",
apirest.MethodAccessTypeAdmin,
a.censusExportIPFSListDBHandler,
); err != nil {
return err
}
if err := a.Endpoint.RegisterMethod(
"/censuses/export",
"GET",
Expand Down Expand Up @@ -203,6 +211,9 @@ func (a *API) enableCensusHandlers() error {
return err
}

// Initialize the map to store the status of the async export to ipfs
censusIPFSExports = make(map[string]time.Time)

return nil
}

Expand Down Expand Up @@ -972,6 +983,9 @@ func (a *API) censusListHandler(_ *apirest.APIdata, ctx *httprouter.HTTPContext)
return ctx.Send(data, apirest.HTTPstatusOK)
}

// censusIPFSExports is a map of ipfs uri to the time when the export was requested
var censusIPFSExports = map[string]time.Time{}

// censusExportDBHandler
//
// @Summary Export census database
Expand All @@ -986,27 +1000,58 @@ func (a *API) censusListHandler(_ *apirest.APIdata, ctx *httprouter.HTTPContext)
func (a *API) censusExportDBHandler(_ *apirest.APIdata, ctx *httprouter.HTTPContext) error {
isIPFSExport := strings.HasSuffix(ctx.Request.URL.Path, "ipfs")
buf := bytes.Buffer{}
if err := a.censusdb.ExportCensusDB(&buf); err != nil {
return err
}
var data []byte
if isIPFSExport {
uri, err := a.storage.PublishReader(ctx.Request.Context(), &buf)
if err != nil {
return err
}
go func() {
log.Infow("exporting census database to ipfs async")
startTime := time.Now()
if err := a.censusdb.ExportCensusDB(&buf); err != nil {
log.Errorw(err, "could not export census database")
return
}
log.Infow("census database exported", "duration (s)", time.Since(startTime).Seconds())
startTime = time.Now()
uri, err := a.storage.PublishReader(context.Background(), &buf)
if err != nil {
log.Errorw(err, "could not publish census database to ipfs")
return
}
log.Infow("census database published to ipfs", "uri", uri, "duration (s)", time.Since(startTime).Seconds())
censusIPFSExports[uri] = time.Now()
}()
var err error
data, err = json.Marshal(map[string]string{
"uri": uri,
"message": "scheduled, check /censuses/export/ipfs/list",
})
if err != nil {
return err
log.Errorw(err, "could not marshal response")
}
} else {
if err := a.censusdb.ExportCensusDB(&buf); err != nil {
return err
}
data = buf.Bytes()
}
return ctx.Send(data, apirest.HTTPstatusOK)
}

// censusExportIPFSListDBHandler
//
// @Summary List export census database to IPFS
// @Description List the IPFS URIs of the census database exports
// @Tags Censuses
// @Accept json
// @Produce json
// @Success 200 {object} object{valid=bool}
// @Router /censuses/export/ipfs/list [get]
func (a *API) censusExportIPFSListDBHandler(_ *apirest.APIdata, ctx *httprouter.HTTPContext) error {
data, err := json.Marshal(censusIPFSExports)
if err != nil {
return err
}
return ctx.Send(data, apirest.HTTPstatusOK)
}

// censusImportHandler
//
// @Summary Import census database
Expand Down
Loading