update response signature

add dupes check
add de-sync checks
This commit is contained in:
Niko Storni 2018-08-31 11:42:15 -04:00
parent c51ed5612d
commit f918f90853
No known key found for this signature in database
GPG key ID: F37FE63398800368
3 changed files with 106 additions and 23 deletions

View file

@ -456,3 +456,15 @@ func (d *Client) NumClaimsInChannel(url string) (uint64, error) {
} }
return channel.ClaimsInChannel, nil return channel.ClaimsInChannel, nil
} }
func (d *Client) ClaimListMine() (*ClaimListMineResponse, error) {
response := new(ClaimListMineResponse)
err := d.call(response, "claim_list_mine", map[string]interface{}{})
if err != nil {
return nil, err
} else if response == nil {
return nil, errors.Err("no response")
}
return response, nil
}

View file

@ -33,15 +33,22 @@ type Support struct {
type Claim struct { type Claim struct {
Address string `json:"address"` Address string `json:"address"`
Amount decimal.Decimal `json:"amount"` Amount decimal.Decimal `json:"amount"`
BlocksToExpiration int `json:"blocks_to_expiration"`
Category string `json:"category"`
ClaimID string `json:"claim_id"` ClaimID string `json:"claim_id"`
ClaimSequence int `json:"claim_sequence"` ClaimSequence int `json:"claim_sequence"`
Confirmations int `json:"confirmations"`
DecodedClaim bool `json:"decoded_claim"` DecodedClaim bool `json:"decoded_claim"`
Depth int `json:"depth"` Depth int `json:"depth"`
EffectiveAmount decimal.Decimal `json:"effective_amount"` EffectiveAmount decimal.Decimal `json:"effective_amount"`
ExpirationHeight int `json:"expiration_height"`
Expired bool `json:"expired"`
Height int `json:"height"` Height int `json:"height"`
Hex string `json:"hex"` Hex string `json:"hex"`
IsSpent bool `json:"is_spent"`
Name string `json:"name"` Name string `json:"name"`
Nout int `json:"nout"` Nout int `json:"nout"`
PermanentUrl string `json:"permanent_url"`
Supports []Support `json:"supports"` Supports []Support `json:"supports"`
Txid string `json:"txid"` Txid string `json:"txid"`
ValidAtHeight int `json:"valid_at_height"` ValidAtHeight int `json:"valid_at_height"`
@ -234,7 +241,9 @@ type ClaimListResponse struct {
LastTakeoverHeight int `json:"last_takeover_height"` LastTakeoverHeight int `json:"last_takeover_height"`
SupportsWithoutClaims []Support `json:"supports_without_claims"` SupportsWithoutClaims []Support `json:"supports_without_claims"`
} }
type ClaimListMineResponse struct {
Claims []Claim `json:"claims"`
}
type ClaimShowResponse Claim type ClaimShowResponse Claim
type PeerListResponsePeer struct { type PeerListResponsePeer struct {

View file

@ -365,9 +365,71 @@ func logShutdownError(shutdownErr error) {
SendErrorToSlack("WALLET HAS NOT BEEN MOVED TO THE WALLET BACKUP DIR") SendErrorToSlack("WALLET HAS NOT BEEN MOVED TO THE WALLET BACKUP DIR")
} }
func hasDupes(claims []jsonrpc.Claim) (bool, error) {
videoIDs := make(map[string]interface{})
for _, c := range claims {
if !util.InSlice(c.Category, []string{"claim", "update"}) || c.Value.Stream == nil {
continue
}
if c.Value.Stream.Metadata == nil || c.Value.Stream.Metadata.Thumbnail == nil {
return false, errors.Err("something is wrong with the this claim: %s", c.ClaimID)
}
tn := *c.Value.Stream.Metadata.Thumbnail
videoID := tn[:strings.LastIndex(tn, "/")+1]
_, ok := videoIDs[videoID]
if !ok {
videoIDs[videoID] = nil
continue
}
return true, nil
}
return false, nil
}
//publishesCount counts the amount of videos published so far
func publishesCount(claims []jsonrpc.Claim) (int, error) {
count := 0
for _, c := range claims {
if !util.InSlice(c.Category, []string{"claim", "update"}) || c.Value.Stream == nil {
continue
}
if c.Value.Stream.Metadata == nil || c.Value.Stream.Metadata.Thumbnail == nil {
return count, errors.Err("something is wrong with the this claim: %s", c.ClaimID)
}
count++
}
return count, nil
}
func (s *Sync) doSync() error { func (s *Sync) doSync() error {
var err error var err error
claims, err := s.daemon.ClaimListMine()
if err != nil {
return errors.Prefix("cannot list claims: ", err)
}
hasDupes, err := hasDupes(claims.Claims)
if err != nil {
return errors.Prefix("error checking for duplicates: ", err)
}
if hasDupes {
return errors.Err("channel has duplicates! Manual fix required")
}
pubsOnWallet, err := publishesCount(claims.Claims)
if err != nil {
return errors.Prefix("error counting claims: ", err)
}
pubsOnDB := 0
for _, sv := range s.syncedVideos {
if sv.Published {
pubsOnDB++
}
}
if pubsOnWallet > pubsOnDB {
return errors.Err("not all published videos are in the database")
}
if pubsOnWallet < pubsOnDB {
SendInfoToSlack("We're claiming to have published %d videos but we only published %d (%s)", pubsOnDB, pubsOnWallet, s.lbryChannelID)
}
err = s.walletSetup() err = s.walletSetup()
if err != nil { if err != nil {
return errors.Prefix("Initial wallet setup failed! Manual Intervention is required.", err) return errors.Prefix("Initial wallet setup failed! Manual Intervention is required.", err)
@ -379,10 +441,10 @@ func (s *Sync) doSync() error {
for i := 0; i < s.ConcurrentVideos; i++ { for i := 0; i < s.ConcurrentVideos; i++ {
s.grp.Add(1) s.grp.Add(1)
go func() { go func(i int) {
defer s.grp.Done() defer s.grp.Done()
s.startWorker(i) s.startWorker(i)
}() }(i)
} }
if s.LbryChannelName == "@UCBerkeley" { if s.LbryChannelName == "@UCBerkeley" {