From 0e269db950dd22314d58ad3de5627b4a8a8040a3 Mon Sep 17 00:00:00 2001 From: Emmanuel T Odeke Date: Fri, 22 Apr 2022 00:30:15 +0100 Subject: [PATCH] eth/tracers/logger: remove unnecessary comparisons in accessList.equal (#24663) This change removes extraneous/unnecessary checks for equality when comparing 2 accessList values A and B. Given that we validate that their lengths of A and B are equal, if so and if every element in A is in B, reflexively every element in B is already in A. If that weren't the case and an element g existed in A but not in B, that would mean that there is an extra element and hence a mathematical contradiction. Fixes #24658 --- eth/tracers/logger/access_list_tracer.go | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/eth/tracers/logger/access_list_tracer.go b/eth/tracers/logger/access_list_tracer.go index 37f71a05abfb..a8908094eb50 100644 --- a/eth/tracers/logger/access_list_tracer.go +++ b/eth/tracers/logger/access_list_tracer.go @@ -62,16 +62,14 @@ func (al accessList) equal(other accessList) bool { if len(al) != len(other) { return false } + // Given that len(al) == len(other), we only need to check that + // all the items from al are in other. for addr := range al { if _, ok := other[addr]; !ok { return false } } - for addr := range other { - if _, ok := al[addr]; !ok { - return false - } - } + // Accounts match, cross reference the storage slots too for addr, slots := range al { otherslots := other[addr] @@ -79,16 +77,13 @@ func (al accessList) equal(other accessList) bool { if len(slots) != len(otherslots) { return false } + // Given that len(slots) == len(otherslots), we only need to check that + // all the items from slots are in otherslots. for hash := range slots { if _, ok := otherslots[hash]; !ok { return false } } - for hash := range otherslots { - if _, ok := slots[hash]; !ok { - return false - } - } } return true }