Iran was NOT bombing its neighbours and demanding Hormuz toll before the war. Not even after it was bombed last June.
If they had not responded strongly, USA/Israel would keep periodically 'mowing the lawn', not acceptable to any country, especially not for a big and proud nation like Iran.
Btw, the US military bases in Gulf countries are legitimate military targets, and have born the brunt of Iran's attacks. It is just that in our western media the focus is on any civilian damages, and almost all damages to military is hushed up.
Iran has no good way to prevent future attacks (nobody sane would believe any agreement signed by USA), their only way is to make sure beyond any doubt that attacking them again will hurt VERY, VERY much. As a side note, getting rid of USA military bases in the Gulf would be beneficial to them in making any future attacks on them more difficult. Hence the (very true!) messaging 'the USA military bases are not there to protect you, but to help them project power over us (and you!), and are only making you a target, reducing your security, not increasing it'.