-
Notifications
You must be signed in to change notification settings - Fork 10
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
disable HandleTransactionAnnouncement #529
Changes from all commits
daa8471
3fe065d
3109d50
bd9aff3
56fdd42
80fdd43
78f4495
f86c786
f213e35
7aeb52a
f57b226
87084dd
9b9ed3f
6f3f467
f81dd40
25e9ede
1cf6098
c976396
5a04485
b2c5c0a
9f37b42
217f41d
3ecc27e
cd9db53
a1d17f9
d8eb773
b9d974a
a6dab6c
8820273
f51f4ec
87413df
07db225
f0e8c29
50c9987
e0464e5
1a6cc93
bc8368c
0c81a11
bf4e845
5bba1c8
2753989
f2f11cd
79a8234
30fb6cd
3f16d93
ff44acc
06cbe81
17f0632
409f1be
de86379
9f16312
fb5608d
6a762eb
d2d59ed
a30ca52
d7017a5
5a3edeb
cc279d5
3af7bef
1980a83
84d76e5
7194db1
025fc1e
98541bb
310aa12
312ae08
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -86,6 +86,14 @@ type Processor struct { | |||||
|
||||||
processMinedInterval time.Duration | ||||||
processMinedBatchSize int | ||||||
|
||||||
orderedDnnouncedTransactions []AnnouncedTransaction | ||||||
announcedTransactionsLock sync.Mutex | ||||||
} | ||||||
|
||||||
type AnnouncedTransaction struct { | ||||||
second uint64 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not actually timestamp, it's simply number of seconds. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's the number of seconds since the Unix epoch. It is used to determine if an object is older than a specific moment in time. Seems like a timestamp to me |
||||||
hash *chainhash.Hash | ||||||
} | ||||||
|
||||||
type Option func(f *Processor) | ||||||
|
@@ -120,8 +128,9 @@ func NewProcessor(s store.MetamorphStore, pm p2p.PeerManagerI, statusMessageChan | |||||
maxRetries: maxRetriesDefault, | ||||||
minimumHealthyConnections: minimumHealthyConnectionsDefault, | ||||||
|
||||||
responseProcessor: NewResponseProcessor(), | ||||||
statusMessageCh: statusMessageChannel, | ||||||
responseProcessor: NewResponseProcessor(), | ||||||
statusMessageCh: statusMessageChannel, | ||||||
orderedDnnouncedTransactions: make([]AnnouncedTransaction, 0), | ||||||
|
||||||
processExpiredTxsInterval: unseenTransactionRebroadcastingInterval, | ||||||
processSeenOnNetworkTxsInterval: seenOnNetworkTransactionRequestingInterval, | ||||||
|
@@ -197,6 +206,7 @@ func (p *Processor) Start() error { | |||||
p.StartProcessExpiredTransactions() | ||||||
p.StartRequestingSeenOnNetworkTxs() | ||||||
p.StartProcessStatusUpdatesInStorage() | ||||||
p.StartCheckingTransactionsInNetwork() | ||||||
p.StartProcessMinedCallbacks() | ||||||
err = p.StartCollectStats() | ||||||
if err != nil { | ||||||
|
@@ -384,6 +394,38 @@ func (p *Processor) StartSendStatusUpdate() { | |||||
}() | ||||||
} | ||||||
|
||||||
func (p *Processor) StartCheckingTransactionsInNetwork() { | ||||||
p.waitGroup.Add(1) | ||||||
ticker := time.NewTicker(100 * time.Millisecond) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Open question: Is it necessary to lock the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Honestly not sure what we need here exactly. Or in other words what's the best time interval to wait before requesting transaction. |
||||||
go func() { | ||||||
defer p.waitGroup.Done() | ||||||
for { | ||||||
select { | ||||||
case <-p.ctx.Done(): | ||||||
return | ||||||
|
||||||
case <-ticker.C: | ||||||
p.announcedTransactionsLock.Lock() | ||||||
for k := 0; k < len(p.orderedDnnouncedTransactions); k++ { | ||||||
if p.orderedDnnouncedTransactions[k].second < uint64(p.now().Unix())-1 { | ||||||
p.logger.Info("requested transaction", slog.String("hash", p.orderedDnnouncedTransactions[k].hash.String())) | ||||||
p.pm.RequestTransaction((p.orderedDnnouncedTransactions[k].hash)) | ||||||
if k == len(p.orderedDnnouncedTransactions)-1 { | ||||||
p.orderedDnnouncedTransactions = []AnnouncedTransaction{} | ||||||
break | ||||||
} | ||||||
} else { | ||||||
p.orderedDnnouncedTransactions = p.orderedDnnouncedTransactions[k:] | ||||||
break | ||||||
} | ||||||
} | ||||||
p.announcedTransactionsLock.Unlock() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reset the ticker at the end |
||||||
ticker.Reset(100 * time.Millisecond) | ||||||
} | ||||||
} | ||||||
}() | ||||||
} | ||||||
|
||||||
func (p *Processor) StartProcessStatusUpdatesInStorage() { | ||||||
ticker := time.NewTicker(p.processStatusUpdatesInterval) | ||||||
p.waitGroup.Add(1) | ||||||
|
@@ -678,9 +720,6 @@ func (p *Processor) ProcessTransaction(ctx context.Context, req *ProcessorReques | |||||
Status: metamorph_api.Status_STORED, | ||||||
}) | ||||||
|
||||||
// Send GETDATA to peers to see if they have it | ||||||
p.pm.RequestTransaction(req.Data.Hash) | ||||||
|
||||||
// Announce transaction to network peers | ||||||
p.logger.Debug("announcing transaction", slog.String("hash", req.Data.Hash.String())) | ||||||
peers := p.pm.AnnounceTransaction(req.Data.Hash, nil) | ||||||
|
@@ -689,6 +728,9 @@ func (p *Processor) ProcessTransaction(ctx context.Context, req *ProcessorReques | |||||
return | ||||||
} | ||||||
|
||||||
// will be requesting transaction after ~2 seconds to get SEEN_ON_NETWORK status | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This operation may be blocking. Can we move it to the end of the processing? Does it make sense? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you mean blocking? It's simple mutex lock nothing complicated here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but we lock the same collection in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry still confused. Yes we lock it in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's assume we have heavy traffic and receive a lot of transactions.
In this case, isn't it a problem that we are delaying the processing of transactions (status updates, responses to the client) until the transactions can be added to the collection? |
||||||
p.DeferRequestTransaction(req.Data.Hash) | ||||||
|
||||||
// update status in response | ||||||
statusResponse.UpdateStatus(StatusAndError{ | ||||||
Status: metamorph_api.Status_ANNOUNCED_TO_NETWORK, | ||||||
|
@@ -704,6 +746,15 @@ func (p *Processor) ProcessTransaction(ctx context.Context, req *ProcessorReques | |||||
p.responseProcessor.Add(statusResponse) | ||||||
} | ||||||
|
||||||
func (p *Processor) DeferRequestTransaction(txHash *chainhash.Hash) { | ||||||
p.announcedTransactionsLock.Lock() | ||||||
p.orderedDnnouncedTransactions = append(p.orderedDnnouncedTransactions, AnnouncedTransaction{ | ||||||
second: uint64(p.now().Unix()), | ||||||
hash: txHash, | ||||||
}) | ||||||
p.announcedTransactionsLock.Unlock() | ||||||
} | ||||||
|
||||||
func (p *Processor) ProcessTransactions(sReq []*store.StoreData) { | ||||||
// store in database | ||||||
err := p.store.SetBulk(p.ctx, sReq) | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add comment why we do not handle INV messages